Hello,
I have a table named TblInvoice which have following columns.
InvoiceID(Primary key), DateofSale, CustomerID, SaleType, TypeofSale.
For transferring data to this table the code is
It code is working well with Button called BtnSave.
I have another table named as TblTest with following columns
InvoiceID(as foreign key), ProductID, ProductName, Qty, Rate, Amount.
Both table are related with InvoiceID.
The datagridview is used to add Products and other columns.
For transferring data to this table the code is
This code is also working with Button called BtnData.
Is there any code for transferring data to these two tables in single query ?
Thanks.
I have a table named TblInvoice which have following columns.
InvoiceID(Primary key), DateofSale, CustomerID, SaleType, TypeofSale.
For transferring data to this table the code is
VB.NET:
con.Close()
Try
con.Open()
If MsgBox("Save Data to database ?", vbYesNo + vbQuestion) = vbYes Then
cmd = New OleDbCommand("Insert into TblInvoice (DateofSale,CustomerID,SaleType,TypeofSale)values('" + TxtDate.Text + "','" + TxtID.Text + "','" + CmbSaleType.Text + "','" + CmbTypeofSale.Text + "') ", con)
Dim a As Integer = cmd.ExecuteNonQuery
If (a > 0) Then
con.Close()
MsgBox("Record Saved Successfully", MsgBoxStyle.Information, MsgBoxStyle.OkOnly)
End If
Else
MsgBox("Record not saved.", MsgBoxStyle.Critical, MsgBoxStyle.OkOnly)
End If
Catch ex As Exception
MsgBox("Error", ex.Message)
Finally
con.Close()
End Try
con.Close()
I have another table named as TblTest with following columns
InvoiceID(as foreign key), ProductID, ProductName, Qty, Rate, Amount.
Both table are related with InvoiceID.
The datagridview is used to add Products and other columns.
For transferring data to this table the code is
VB.NET:
For i As Integer = 0 To DataGridView1.Rows.Count - 2 Step +1
cmd = New OleDbCommand("INSERT INTO TblTest(InvoiceID,ProductID,ProductName,Qty,Rate,Amount) VALUES (@InvoiceID,@ProductID,@ProductName,@Qty,@Rate,@Amount)", con)
cmd.Parameters.Add("@InvoiceID", OleDbType.Integer).Value = DataGridView1.Rows(i).Cells(0).Value.ToString()
cmd.Parameters.Add("@ProductID", OleDbType.Integer).Value = DataGridView1.Rows(i).Cells(1).Value.ToString()
cmd.Parameters.Add("@ProductName", OleDbType.Char).Value = DataGridView1.Rows(i).Cells(2).Value.ToString()
cmd.Parameters.Add("@Qty", OleDbType.Char).Value = DataGridView1.Rows(i).Cells(3).Value.ToString()
cmd.Parameters.Add("@Rate", OleDbType.Char).Value = DataGridView1.Rows(i).Cells(4).Value.ToString()
cmd.Parameters.Add("@Amount", OleDbType.Char).Value = DataGridView1.Rows(i).Cells(5).Value.ToString()
cmd.ExecuteNonQuery()
Next
con.Close()
Is there any code for transferring data to these two tables in single query ?
Thanks.