Hi guys,
wondered if anyone could help, or point me in the right direction please,
i want to insert data from the datagridview to the access database, that datagridview is not bound to anything, i insert data from textboxes to the DGV, and want them to insert into the DB, the form i am working with is a order form, and the DGV is to be the sales
Private Sub btn_Add_Click(sender As System.Object, e As System.EventArgs) Handles btn_Add.Click
DataGridView1.Rows.Add(cbox_Product.Text, tbox_Sale_Price.Text, tbox_Qty.Text, tbox_Discount.Text, tbox_SubTotal.Text, tbox_SalesID.Text)
Dim con As New OleDb.OleDbConnection '"con" variable holds the Connection Object
Dim dbProvider As String 'creates provider variable
Dim dbSource As String
dbProvider = "Provider = Microsoft.ACE.OLEDB.12.0;" 'specifies the provider technology
dbSource = "Data Source = E:\VB.NET\Computer First Ade VB.net\Computer First Ade\Computer First Ade\CFA_DB.mdb" 'specifies the path to the Database
con.ConnectionString = dbProvider & dbSource 'creates the connection string'creates source variable
'opens connection
con.Open()
'creates new variable and specifies which technology to use and shows the file path to the database
Dim Connection As New OleDb.OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0" & _
"Data Source = E:\VB.NET\Computer First Ade VB.net\Computer First Ade\Computer First Ade\CFA_DB.mdb")
'If con.State = ConnectionState.Open Then
' con.Open()
'End If
Dim InsertCommand As New OleDb.OleDbCommand("INSERT INTO tbl_Sales( sal_Product_Code, sal_Price, sal_Quantity, sal_Discount, sal_Subtotal)" & _
" VALUES( @sal_Product, @sal_Price, @sal_Quantity, @sal_Discount, @sal_Subtotal)", con)
'Insert command, adds what ever is in the textbox
InsertCommand.Parameters.Add(New OleDb.OleDbParameter("@sal_Product", cbox_Product.Text)) 'to the specified column(item) from the SQL query
InsertCommand.Parameters.Add(New OleDb.OleDbParameter("@sal_Price", tbox_Sale_Price.Text))
InsertCommand.Parameters.Add(New OleDb.OleDbParameter("@sal_Quantity", tbox_Qty.Text))
InsertCommand.Parameters.Add(New OleDb.OleDbParameter("@sal_Discount", tbox_Discount.Text))
InsertCommand.Parameters.Add(New OleDb.OleDbParameter("@sal_Subtotal", tbox_SubTotal.Text))
InsertCommand.ExecuteNonQuery() 'executes this insert command
con.Close() 'closes connection
MessageBox.Show("Inserted") 'displays the messagebox
End Sub
any ideas?