Link to home
Start Free TrialLog in
Avatar of aarontham
aarontham

asked on

VB.net 2008 update dataset to MySql

i populate an datagridview with below code. then user will do some edit on the datagridview . after the edit i need an button to update back the data to MySql. pls provide code.
Dim cnString3 As String = My.Settings.DataCon
        Dim strQuery3 As String = "SELECT * From t_user"
 
        Using adapter As New MySqlDataAdapter(strQuery3, cnString3)
 
            Dim myDataSet As New DataTable()
 
            Try
                adapter.Fill(myDataSet)
            Catch exError As Exception
 
                MessageBox.Show(exError.Message, _
                Me.Text, _
                MessageBoxButtons.OK, _
                MessageBoxIcon.Error)
                Exit Sub
            End Try
 
              'FILL DATAGRIBVIEW FROM DATABASE
            Me.DataGridView1.DataSource = myDataSet
 
        End Using

Open in new window

Avatar of amar31282
amar31282
Flag of India image

Try this One to update data
Dim cnString3 As String = My.Settings.DataCon
        Dim strQuery3 As String = "Update table t_user set column1=@column1value, column2=@column2value..... where condition"
 
	Dim cmd As New OleDbCommand()
        
        cmd.Parameters.Add("@column1valuer", OleDbType.VarChar).Value = DatagridColumn1.Text
        cmd.Parameters.Add("@column2value", OleDbType.VarChar).Value = DatagridColumn1.Text
 
 
            Try
            cmd.CommandText = strQuery3 
            cmd.Connection = objConnection;
            cmd.ExecuteNonQuery();
 
            Catch exError As Exception
 
                MessageBox.Show(exError.Message, _
                Me.Text, _
                MessageBoxButtons.OK, _
                MessageBoxIcon.Error)
                Exit Sub
            End Try

Open in new window

Avatar of aarontham
aarontham

ASKER

i prefer to use  adaptor.Update. but i can't get it work. Pls provide code which use button to fire the save event.
ASKER CERTIFIED SOLUTION
Avatar of amar31282
amar31282
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial