简体   繁体   中英

c# winforms datagridview databinding

I must be missing something really obvious but I have narrowed down the problem to the simplest possible repro case.

I am trying to debug an old Winforms 2.0 app that has no docs and was written, well a long time ago. I am using VS 2012.

I have a SQLCE 4.0 DB with 4 small tables in it. I created a DataSet by adding the DB to the DataSources window.

I then added a bindingSource and DataGridView to the form bound them together and pointed them at the DataSource and they added a strongly typed DataSet.

If I manually enter the data into the SDF using Server Explorer and then run the app I see all the data in the grid.

BUT if I enter data into the grid, one row or many it does not get committed to the DB.

If I do all this in code and don't use any of the autogenerated stuff I can get it to work but the existing app uses all the autogenerated stuff and I don't feel like going back and fixing 20+ grids by hand if this is the only pattern I can get to work.

I feel like I must be missing something really simple that writes are not getting through to the DB, but I can't find it.

Thx

Maybe like this .. In VB

When you have this ..

Private bindingSource1 As New BindingSource()
Private dataAdapter As New SqlDataAdapter()
Dim table As New DataTable()

And doing this

Me.dataAdapter.Fill(table)
Me.bindingSource1.DataSource = table

Then user made some changes in your bindingsource then don't forget

Me.dataAdapter.Update(CType(Me.bindingSource1.DataSource, DataTable))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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