hi experts
i m using ms access data base as back and in my new project,
this is my code

Imports System.Data.OleDb

Public Class st_name
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim thismode As Integer

    Private Sub st_name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tcon()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'TODO: This line of code loads data into the 'Blood_bank_ds.st_name' table. You can move, or remove it, as needed.
        Me.St_nameTableAdapter.Fill(Me.Blood_bank_ds.st_name)

        TextBox1.Text = ""
        TextBox1.Focus()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            'cn.Open()
            cmd = New OleDbCommand("", cn)
            If thismode = 0 Then
                cmd = New OleDbCommand("insert into st_name (" _
                                        & "st_name, " _
                                        & "us_code) values (" _
                                        & "'" & Trim(TextBox1.Text) & "',  " _
                                        & tus_code & ")", cn)
            Else
                cmd.CommandText = "update st_name set " _
                                        & "st_name = '" & Trim(TextBox1.Text) & "', " _
                                        & "us_code = " & tus_code & " where st_id = " & thismode


            End If
            cn.Open()
            cmd.ExecuteNonQuery()
            'Dim icount As Integer
            'icount = cmd.ExecuteNonQuery
            'MessageBox.Show(icount)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            cn.Close()
            Button2.PerformClick()
        End Try
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        thismode = DataGridView1.CurrentRow.Cells(0).Value
        TextBox1.Text = Trim(DataGridView1.CurrentRow.Cells(1).Value)
        TextBox1.Focus()
    End Sub
End Class

with this code insert command run properly and saved data sill be show in datagridview bu not save in mdb table , when i show in data table data is not shon

Assuming that your datagridview is databound, and it's datasource is Me.Blood_bank_ds.st_name.
Have you tried using a BindingSource object?

Public Class st_name
   Private source As New BindingSource
   
   Public Sub st_name_Load(....
      DataGridView1.DataSource = source
   End Sub


   Private Sub Button2_Click(.....
      Me.St_nameTableAdapter.Fill(Me.Blood_bank_ds.st_name)

      'This will update the bindingsource, and because it's already tied to the datagrid the information in will be updated.
      source = Me.Blood_bank_ds.st_name
   End Sub
End Class
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.