**

i try to insert 10 record under the field year and actual data but only the first text from text1 is entering inside

**

        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
        dataFile = "db7exmpl.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString
        myConnection.Open()
        Dim str As String
        'str = " INSERT INTO tb (Years) VALUES('" & TextBox1.Text & "," & TextBox3.Text & "," & TextBox5.Text & "');"
        str = "insert into tb ([Years], [Actual_data]) values (?, ?)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)

        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox1.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox3.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox5.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox7.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox9.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox11.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox13.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox15.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox17.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Years", CType(TextBox19.Text, String)))

        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox2.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox4.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox6.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox8.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox10.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox12.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox14.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox16.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox18.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_data", CType(TextBox20.Text, String)))
        Try
            cmd.ExecuteNonQuery()
            'myConnection.Close()
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

i try to insert 10 record under the field year

Adding ten parameters to one query (as you coded it) isn't the way to do this.

You'll want to run the query ten times with different parameters.

please how do i accomplish it, all i want is all the record to be save under the field year at the same time

  1. Create a command like the one you wrote already.
  2. Add one "Years" parameter.
  3. Add one "Actual_data" parameter (the one that goes with the "Years" parameter).
  4. Execute the command.
  5. Go back to step 1 for the rest of the year/data pairs.
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.