i have a big problem here when i want to insert 6 data into 6 different row in 1 click.
in field @ form it have name, staff no.,items, quantity and date.
We can select 6 items to insert which i use ComboBox for save the data in form.
In this case, each name can choose 6 items in one time and i want to save it in database just in 1 click. that mean it will put a same name in 6 rows in a table.

the look like this but it not complete...

Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\database.mdb")
        Dim sql As String = String.Empty
sql = "insert into Pengurus(name, staff no.,items, quantity, date )" & "values ('" & txtQtt.Text & "', '" & txtDate.Text & "') "

            Try

                conn.Open()

                Dim Command As New OleDbCommand(sql, conn)
                Command.ExecuteNonQuery()
                conn.Close()
           end Try

but it only insert 1 item...

Edited 5 Years Ago by __avd: Added [code]..[/code] tags.

what u mean about 6 data here?
6 rows added when you click add or 6 data (6 fields) in on row?

sql = "insert into Pengurus(name, staff no.,items, quantity, date )" & "values ('" & txtQtt.Text & "', '" & txtDate.Text & "') "

in your sql statment you just insert 2 value there..
also you want to insert data from combo box? so in your combo box just contain 6 items ? if less or more than 6 items in combobox which item that u want to insert?
and you want insert from which combo box to what field?

what u mean about 6 data here?
6 rows added when you click add or 6 data (6 fields) in on row?

in your sql statment you just insert 2 value there..
also you want to insert data from combo box? so in your combo box just contain 6 items ? if less or more than 6 items in combobox which item that u want to insert?
and you want insert from which combo box to what field?

i mean i got 6 combobox in 1 form..

you didn't answer my other question.
you want insert from which combo box to what field?

Add parameters to the OldCommand and use the correct values for each of them (you said you have comboBoxes (in your upper example are textBoxes).
This is the code that should work:

Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=" + Application.StartupPath & "\database.mdb")
Dim sql As String = String.Empty
sql = "insert into Pengurus(name, staffNo)" & "values (@value1, @value2) "
Try
	conn.Open()
	Dim Command As New OleDbCommand(sql, conn)

	'adding parameters:
	Command.Parameters.Add("@value1", OldDbType.VarChar, 50).Value = comboBox1.SelectedItem.ToString()
	Command.Parameters.Add("@value2", OleDbType.Int).Value = comboBox2.SelectedItem.ToString()
	Command.ExecuteNonQuery()
	conn.Close()
Catch
End Try

I have a problem when inserting 2 combobox value into 1 column of sql in one click.

string qr="insert into tom values("+textBox1.Text+",'"+textBox2.Text+"',"+cmb1.SelectedItem+" & "+cmb2.SelectedItem+" & "+cmb3.SelectedItem+")";

Please help.

Print the value of qr, then post the results here along with the "problem" you are having. I presume some sort of syntax error?

This article has been dead for over six months. Start a new discussion instead.