Help how to save data more than one at the same time

  • Thread starter Thread starter clynnekent
  • Start date Start date
C

clynnekent

Guest
Good day everyone,anyone can help me how to save data more than one at the same time.
I have Tools ID,Tools Name and Tools Quantity in the Form that I created.

Ex. I was inputed in the quantity 2 value then the Tools ID at Tools Name will save in the database
2 rows at the same time with same data.

I have this code like this but I have an error in Primary key which is duplication.

Dim i As Integer
For i = 1 To txtquantity.Text

cmd = New OleDbCommand
cmd.CommandText = " insert into tblsticker values (Sticker_id,Sticker_toolsid,Sticker_toolsname) "
cmd.Parameters.AddWithValue("@Sticker_id", autogeneratesticker)
cmd.Parameters.AddWithValue("@Sticker_toolsid", txttoolsid.Text)
cmd.Parameters.AddWithValue("@Sticker_toolsname", txttoolsname.Text)
cmd.Connection = cn
cmd.ExecuteNonQuery()
MessageBox.Show("Sticker Successfully Saved!")
Next

I was thinking and trying Auto Number in the MS access database and not include the Sticker ID which is the primary key
but I have an error like this: Number of query values and destination field are not the same.

Dim i As Integer
For i = 1 To txtquantity.Text

cmd = New OleDbCommand
cmd.CommandText = " insert into tblsticker values (Sticker_toolsid,Sticker_toolsname) "
cmd.Parameters.AddWithValue("@Sticker_toolsid", txttoolsid.Text)
cmd.Parameters.AddWithValue("@Sticker_toolsname", txttoolsname.Text)
cmd.Connection = cn
cmd.ExecuteNonQuery()
MessageBox.Show("Sticker Successfully Saved!")
Next

I hope anyone can help me of my problem or other way how to do it. I'm using VB 2010 with MS Access database.

Thank you
clynnekent

Continue reading...
 
Back
Top