3

I have a database called DB.mdf, in my program I use this code to insert a new row in this database:

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

ipadap.InsertQuery(ip);

InsertQuery is: 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

Marco
  • 22,856
  • 9
  • 75
  • 124
chianta
  • 123
  • 1
  • 2
  • 12
  • 2
    Are you sure this is correct? INSERT INTO [IP] ([ID], [indirizzo]) VALUES (0, @indirizzo); I see that you pass Id of 6 in your code. – Thanos Markou Apr 27 '15 at 10:05
  • Yes, the code is correct, I haven't any errors. It loads correctly on Dataset but not loads the data on the database – chianta Apr 27 '15 at 10:14

1 Answers1

1

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.

Thanks to all.

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

chianta
  • 123
  • 1
  • 2
  • 12