Datagrid and database update error

Locutus

Member
Joined
Jan 25, 2012
Messages
5
Programming Experience
Beginner
Hi.

I have datagrid and a button in my wpf window. I' d like to update my database after user make changes in datagrid.
But instead of update I'm getting "the UpdateCommand affected 0 of the expected 1 records." error.
If i comment a line number 19 I get a "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." error

My database file in SQLITE has a primary key. I spent couple days and I've no idea what is wrong with my code.
I hope someone help me and indicate my mistakes.

Best Regards

This is my code :

------------------------------------------------------------------------------------------------------------------

  1. Class MainWindow
  2. Public con As New System.Data.SQLite.SQLiteConnection("Data Source = C:\database.s3db")
  3. Public da As New System.Data.SQLite.SQLiteDataAdapter("Select * from Customers", con)
  4. Public ds As New System.Data.DataSet
  5. Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
  6. con.Open()
  7. da.Fill(ds, "Customers")
  8. con.Close()
  9. datagridCustomers.ItemsSource = ds.Tables("Customers").DefaultView
  10. End Sub
  11. Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnUpdate.Click
  12. Dim cb As New System.Data.SQLite.SQLiteCommandBuilder(da)
  13. da.Update(ds, "Customers")
  14. End Sub
  15. End Class

-----------------------------------------------------------------------------------------------------------------
 
Hi.
My mistake I meant line number 12. All my code has 15 lines

After spent a night on this problem finally I resolved it.
The problem was filling table with data using SQLiteman software.
In my datagrid I have column named "DATE_BIRTH" and this is a DATE type.
When I was filling it with data in SQLiteman I made mistake not adding a 00:00:00 on ending row
Maybe this 2 pictures show what I mean

good.JPGbad.JPG

After adding 00:00:00 everything works perfectly.

Regards
 
Back
Top