Hi, I have one form with multiple reading data (using BindingSource) and I want to store those data + some text entry to third table (also using BindingSource DataGrid)

Is it possoble to do that using sql statement ? I have connection to database. Picture is to show what I have on my mind.

If someone can give me example, just as guidelines it would be great.

foe example, how to save into database
combobox1.text (PID)
textbox1.text (PVAL)
combobox3.text (Customer)

This is code on my form from attachment

Public Class Form2
    Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\invoicedb.accdb")

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()
        Form1.Show()

    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'InvoicedbDataSet.rac' table. You can move, or remove it, as needed.
        Me.RacTableAdapter.Fill(Me.InvoicedbDataSet.rac)

        Try
            con.Open()

            If con.State = ConnectionState.Open Then
                Label5.Text = "Connected"
            Else
                Label5.Text = "Not Connected"

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Label5.Text = "Not Connected"
        Finally
            con.Close()

        End Try
        'TODO: This line of code loads data into the 'InvoicedbDataSet.invoice' table. You can move, or remove it, as needed.
        Me.InvoiceTableAdapter.Fill(Me.InvoicedbDataSet.invoice)
        'TODO: This line of code loads data into the 'InvoicedbDataSet.customer' table. You can move, or remove it, as needed.
        Me.CustomerTableAdapter.Fill(Me.InvoicedbDataSet.customer)
        'TODO: This line of code loads data into the 'InvoicedbDataSet.company' table. You can move, or remove it, as needed.
        Me.CompanyTableAdapter.Fill(Me.InvoicedbDataSet.company)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub
End Class

Thanks

vb.png

OK, I got some help on this and code goes

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User1\Desktop\database.accdb")
        Try
            Dim sql As String
            Dim cmd As New OleDb.OleDbCommand
            con.Open()
            sql = "INSERT INTO second (ID,Name,Description,) VALUES ('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "')"
            cmd.Connection = con
            cmd.CommandText = sql
            Dim i As Integer = cmd.ExecuteNonQuery
            If i > 0 Then
                ' MsgBox("Added new records")
                Me.TextBox1.Text = ""
                Me.TextBox2.Text = ""
                Me.TextBox3.Text = ""
                Dim dt As New DataTable
                Dim da As New OleDb.OleDbDataAdapter
                sql = "SELECT * FROM second"
                cmd.Connection = con
                cmd.CommandText = sql
                da.SelectCommand = cmd
                da.Fill(dt)
                DataGridView1.DataSource = dt
            Else
                MsgBox("No records Added")
            End If
        Catch ex As Exception

            MsgBox(ex.Message)
        Finally
            con.Close()
        End Try
    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.