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

Are you getting any error messages?

Could you post them and the line numbers?

For the code i have posted there is no error message
it shows updated successfully....but it is not updating it

if i comment the whole form3_visiblechanged function then error
in 77th line i.e
i = adp.Update(ds, Form1.TextBox2.Text & "_att")
in the try block of the button1_click

error message is:
dynamic generation for the update command is not supported against a select command that does not return any key column information.

I suggest you use the same Command Object (cmd) , the same Adapter (adp) and the same Dataset (ds) in the code for event Form3_VisibleChanged.

Try it and let me know if it worked.

Perhaps you need to use single quotes in your sql string?

eg:
"SELECT * FROM Table WHERE TEXTID = ' " & me.Textbox.TEXT & " ' ORDER BY DATE"

Hope that helps

I got it.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.