Hi all
I have a script to update the value from datagridview to database
I do use a button insert ToolStripButton
but not working
hope people to help
thank !

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

        conn = New SqlConnection("")
        conn.Open()
        Dim query As [String] = "SELECT * FROM dtaEmployees"
        da = New SqlDataAdapter(query, conn)
        Dim cb As New SqlCommandBuilder(da)
        dt = New DataTable()
        da.Fill(dt)
        C1FlexGrid1.DataSource = dt
        conn.Close()

    End Sub
  Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked
        Select Case e.ClickedItem.Name
            Case "ToolStripButton1" '---> button insert
                da.Update(dt)

        End Select
    End Sub

OK. Poof poof.

So I thought I'd check and came up with this which works.

Public Class Form1
    Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\DATA\b040\b040_be.accdb")
    Dim da As New OleDb.OleDbDataAdapter
    Dim builder As New OleDb.OleDbCommandBuilder(da)
    Dim ds As New DataSet
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        connection.Open()
        da.SelectCommand = New OleDb.OleDbCommand("select * from klanten", connection)
        da.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        builder.GetUpdateCommand()
        da.Update(ds)
    End Sub
End Class

I aslo ran it without the builder.getupdatecommand and that seems to work too.

Maybe your problem is that you close the connection. It's a bit hard to understand how you are set from your code alone, maybe you could give us more details.

Take care and good luck.

I think Perplexed is saying right this problem seems due to closing the connection but if you provide few more details then it would be easier to find its root...

You may also try to look at following code

Public Class Form1

    Dim row As Integer
    Dim col As Integer
    Dim currentTime As System.DateTime = System.DateTime.Now
    Dim DataSet1 As New DataSet()
    'Dim com As New OleDb.OleDbCommandBuilder(OleDbDataAdapter1)
    Dim SQLString As String = "SELECT * FROM Table1"
    Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\members.accdb;User ID=admin"
    Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
    Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OleDBConn1.Open()
        OleDbDataAdapter1.Fill(DataSet1, "Table1")
        DataGridView1.DataSource = DataSet1.Tables("Table1")
        TextBox1.Text = currentTime

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataSet1.Tables("Table1").AcceptChanges()
        OleDbDataAdapter1.Update(DataSet1, "table1")
        Dim item As New DataGridViewRow
        DataGridView1.AllowUserToAddRows = True
        item.CreateCells(DataGridView1)


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OleDbDataAdapter1.AcceptChangesDuringUpdate = True
        'OleDbDataAdapter1.UpdateCommand("table1")
        Dim j As Integer
        j = 0
        DataSet1.Tables("Table1").Rows(j).Item(1) = TextBox2.Text

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim i As Integer
        i = 0
        DataSet1.Tables("Table1").Rows(i).Delete()

    End Sub

thanks,
why not use this command in the event toolstripbutton_click
if I use Button_Click work very well, but I want to put all the function buttons on a toolstrip.

you can try this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim btnSomething As New ToolStripButton

        btnSomething.Text = "Test 1"
        btnSomething.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
        btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
        btnSomething.ToolTipText = "This is Just a Test"

        Dim btnSomething2 As New ToolStripButton
        btnSomething2.Text = "Test 2"
        btnSomething2.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
        btnSomething2.TextImageRelation = TextImageRelation.ImageAboveText
        btnSomething2.ToolTipText = "This is Just a Test again"

        ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
        ToolStrip1.Items.Add(btnSomething)
        ToolStrip1.Items.Add(btnSomething2)
        ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
        'ToolStrip1.Items.Add("Test", Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico"))

    End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        Me.Validate()
        DataGridView1.EndEdit()
        da.Update(dt)
        MsgBox("Data Updated!!")
        Me.BindGrid()
    End Sub
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.