Please Check the code and reply what is wrong in the update code
Try block is executed successfully........but it is not being updated.
Public Class Form3
Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=attend_ap; User=root;Password=;")
Dim cmd, cmd2 As Odbc.OdbcCommand
Dim adp, adp2 As Odbc.OdbcDataAdapter
Dim ds, ds2 As New DataSet
Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form1.Close()
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.Open()
cmd = New Odbc.OdbcCommand
cmd.Connection = cn
cmd.CommandText = "Select * from " & Form1.TextBox2.Text & "_att"
ds = New DataSet
adp = New Odbc.OdbcDataAdapter(cmd)
Try
adp.Fill(ds, Form1.TextBox2.Text & "_att")
Catch ex As Exception
MsgBox("Invalid Table name")
Me.Close()
End Try
Me.DataGridView1.DataSource = ds
Me.DataGridView1.DataMember = Form1.TextBox2.Text & "_att"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
Form2.Show()
End Sub
Private Sub Form3_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
cmd2 = New Odbc.OdbcCommand
cmd2.Connection = cn
cmd2.CommandText = "Select * from " & Form1.TextBox2.Text & "_att"
ds2 = New DataSet
adp2 = New Odbc.OdbcDataAdapter(cmd2)
Try
adp2.Fill(ds2, Form1.TextBox2.Text & "_att")
Catch ex As Exception
MsgBox("Invalid Table name")
Me.Close()
End Try
Me.DataGridView1.DataSource = ds2
Me.DataGridView1.DataMember = Form1.TextBox2.Text & "_att"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)
' Dim cmdbuilder2 As New Odbc.OdbcCommandBuilder(adp2)
Try
i = adp.Update(ds, Form1.TextBox2.Text & "_att")
' cmd.ExecuteNonQuery()
' i = adp2.Update(ds2, Form1.TextBox2.Text & "_att")
MsgBox("records updated sucessfully")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Me.Label2.Text = Form1.TextBox2.Text
End Sub
End Class