tags:

views:

130

answers:

1

Hi to all!

I want to insert row into table using linq. I wrote this code

var db = ((Table<PersonAddress>)personAddressBindingSource.DataSource);
db.InsertOnSubmit(new PersonAddress { Address = "abc", PersonId = 5 });

DataGridView connected to personAddressBindingSource. but when run above code, dataGridView not show new row before call SubmitChanges();

Also grid not refresh after call SubmitChanges(), but when get data again from db it's ok by this code

DataClasses1DataContext db = new DataClasses1DataContext();
personAddressBindingSource.DataSource = db.PersonAddresses;

Could you please help me.
Thanks

+1  A: 

Hi, i suppose that you run your db.SubmitChanges() after the InsertOnSubmit statement? The GridView datasource does not automatically updated its datasource so you need to do that manually.

Not having Visual Studio installed at the moment i this there is some Refresh() method on the datasource. But calling GridView.DataBind() should also reload the data.

Hope that helps!

Jonas Cannehag