简体   繁体   English

C#TableAdapter不插入和更新

[英]C# TableAdapter doesn't insert and update

I have a database called DB.mdf, in my program I use this code to insert a new row in this database: 我有一个名为DB.mdf的数据库,在我的程序中我使用此代码在此数据库中插入一个新行:

DBDataSet ds = new DBDataSet();
DBDataSetTableAdapters.IPTableAdapter ipadap = new DBDataSetTableAdapters.IPTableAdapter();

ipadap.InsertQuery(ip);

InsertQuery is: INSERT INTO [IP] ([ID], [indirizzo]) VALUES (0, @indirizzo); InsertQuery是: INSERT INTO [IP] ([ID], [indirizzo]) VALUES (0, @indirizzo);

The program executes all steps, but not inserts the row on database. 程序执行所有步骤,但不在数据库中插入行。 Why? 为什么?

UPDATE Now I have tried this code: 更新现在我尝试了这段代码:

DBDataset.IPRow newRegionRow;
newRegionRow = db.IP.NewIPRow();
newRegionRow.ID = "6";
newRegionRow.indirizzo = "NorthWestern";
// Add the row to the Region table
this.db.IP.Rows.Add(newRegionRow);
// Save the new row to the database
this.ipadap.Update(this.db.IP);

And in this case not write a new row in database 在这种情况下,不要在数据库中写入新行

I have found the error!!! 我发现了错误!!! I didn't know that Visual Studio, during develop, create a copy of database in /bin and it work with the copy of database. 我不知道Visual Studio在开发期间在/ bin中创建了一个数据库副本,它可以使用数据库副本。

Thanks to all. 谢谢大家。

https://msdn.microsoft.com/en-us/library/ms246989.aspx https://msdn.microsoft.com/en-us/library/ms246989.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM