1

I have two tables and the form contains a text box so I need to add rows of Table 1 to Table 2 and taking the value in the text box for each row is added to Table 2.

i have insert syntax but it is need to modification:

INSERT INTO table2(column3,column4) 
SELECT column1 + @parameter 
FROM table1 
WHERE column2=true

table1: column1 column2

table2: column3 column4

Form1: it have textbox1

the full code :

Dim con As New OleDbConnection
Dim cmd As New OleDbCommand
Try
    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\DellXPS\Desktop\mDB.accdb"

    con.Open()
    cmd.Connection = con
    cmd.CommandText = "INSERT INTO table2(column3,column4) SELECT column1 + @parameter FROM table1 WHERE column2=true"

    cmd.Parameters.Add("@parameter",  OleDbType.VarChar).Value = TextBox1.Text
    cmd.ExecuteNonQuery()
Catch ex As Exception
    MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
    con.Close()
End Try

i think the wrong in insert syntax ,, hop to corrected

1
  • i found the right code cmd.CommandText = "INSERT INTO table2(column3, column4) SELECT column1, @parameter FROM table1 WHERE column2=true" that is it :) Commented Feb 23, 2012 at 12:32

1 Answer 1

1

Use following code to add parameter with value in command:

cmd.Parameters.AddWithValue("@parameter",TextBox1.Text);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.