I was able to insert a single row from datagrid but when i try to select 2 or more rows its just inserting the first row. How will I save multiple rows in the sql table, could somebody help me. Here's my code...
For ex.
3 products in one OR Number
1.Garlic Bread
2.Soda
3.Spaghetti
3 orders under OR No. 12345
Dim sqlconn As New SqlClient.SqlConnection
Dim cmdrecords1 As New SqlCommand
sqlconn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename= C:\EUGENE\JJProject\SK.mdf ;Integrated Security=True;Connect Timeout=30;User Instance=True"
Try
sqlconn.Open()
Catch ex As Exception
MsgBox("SQL Error Connection", MsgBoxStyle.Critical, " Database Connection")
End Try
If tx2.Text = "" Or tx3.Text = "" Or ComboBox1.Text = "" Or TextBox1.Text = "" Then
MsgBox("Incomplete Information!", MsgBoxStyle.OkOnly, "Message")
Else
If MsgBox("Post Payment?", MsgBoxStyle.YesNo, "Add Record") = MsgBoxResult.No Then
Else
Dim i As Integer
i = D2.CurrentRow.Index 'Datagrid count
cmdrecords1 = sqlconn.CreateCommand
cmdrecords1.CommandText = "INSERT INTO Master2 (product, price, qty, unit, ORdate, OrNo, total, gtotal, tableNo, itemNo) VALUES ('" & Trim(D2.Item(0, i).Value) & "', '" & Trim(D2.Item(1, i).Value) & "', '" & Trim(D2.Item(2, i).Value) & "', '" & Trim(D2.Item(3, i).Value) & "','" & Trim(tx2.Text) & "', '" & Trim(tx3.Text) & "', '" & Trim(tx4.Text) & "', '" & Trim(tx6.Text) & "', '" & Trim(ComboBox1.Text) & "', '" & Trim(TextBox1.Text) & "')"
check = cmdrecords1.ExecuteReader.RecordsAffected()
If check <> 0 Then
End If
MsgBox("Payment posted.", MsgBoxStyle.OkOnly, )