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...

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
Member Avatar for prathamesh3090

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?

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.