Question unable to update DataTable when AllowUserToAddRows property is false

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
Hi
There is a DataGridView in my form with a DataTable as a DataSource . This DataTable is linked to a DataBase. I set the AllowUserToAddRows property to false , so when I run the program there is no any row in dgv . I use the code below to add new row :
VB.NET:
MyDataTable.Rows.Add()
So a new row add to dgv (in fact this row add to datatable) . First I fill the cells of this row with right values . But when I try to update the DataTable this new row don't add to database whereas if AllowUserToAddRows property set to true , when I run the program there is a row in dgv and everything is OK.I want to add the row manually in the program .
Thanks
 
The code that you say you use wouldn't compile, so obviously you don't use that code. If you're going to post code then post the actual code you're using and not an approximation of it. If you add a DataRow to the DataTable properly then it will save properly, regardless of how it got there. Obviously you're doing something wrong but if you don't show us what you're doing then we can't possibly know what's wrong with it. Show us the actual code you're using to create, populate, add and save this record.
 
I have a feeling that what you were actually doing was adding a row to the grid rather than adding a row to the table, as your code indicated.
 
Back
Top