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 :
Code:
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
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,147
Location
Sydney, Australia
Programming Experience
10+
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.
 

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
Thanks , the problem is solved , by using Row.EndEdit
 
Top Bottom