I am trying to populate a datagridview from an sql statement (which I have achieved) but then want to be able to update the contents of the cells by entering data and saving the changes back to the database.
I am populating the datagridview with the following code:
And these are the functions in a separate class file:
At the moment it will only let me update the memberid.
If I try to change the id, name, dateordered, or dateprinted columns and then run the update function I do not get any errors but when i reload the data the changes have not been saved.
Could someone point me in the right direction here?
Thanks.
I am populating the datagridview with the following code:
VB.NET:
Private Sub get_data()
db.queryDb("SELECT customer.id, CONCAT (customer.forename, ' ', customer.surname) as name, customer.memberid, DATE_FORMAT(membercard.dateordered,'%d/%m/%Y') as dateordered, DATE_FORMAT(membercard.dateprinted,'%d/%m/%Y') as dateprinted FROM customer,membercard WHERE customer.id = membercard.customerid AND dateprinted = YEAR(0000)", dgvMembercard, 500)
End Sub
And these are the functions in a separate class file:
VB.NET:
'create data adapter
Dim da As MySqlDataAdapter
'create dataset
Public ds As DataSet = New DataSet
Public Function queryDb(ByVal sqlQuery As String, ByRef grid As DataGridView, ByVal limit As String) As Boolean
Try
da = New MySql.Data.MySqlClient.MySqlDataAdapter(sqlQuery, dbxConn)
'create command builder
Dim cb As MySql.Data.MySqlClient.MySqlCommandBuilder = New MySql.Data.MySqlClient.MySqlCommandBuilder(da)
'fill dataset
da.Fill(ds, "Customers")
grid.DataSource = ds
grid.DataMember = "Customers"
Return True
Catch ex As MySqlException
MessageBox.Show(ex.ToString)
Return False
End Try
End Function
Public Function Update_DGV()
Try
'update customers table
da.Update(ds, "Customers")
Catch ex As Exception
Return False
MessageBox.Show(ex.ToString)
End Try
Return True
End Function
At the moment it will only let me update the memberid.
If I try to change the id, name, dateordered, or dateprinted columns and then run the update function I do not get any errors but when i reload the data the changes have not been saved.
Could someone point me in the right direction here?
Thanks.