i need to insert values to a table that i can select at runtime.. here is my code
Please help
VB.NET:
Dim ConnectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=***\ClubDatabase.mdf;Integrated Security=True;User Instance=True"
Dim pid, name, qty, cp As String
Const strInsert As String = "INSERT INTO [111]([Name], [Qty], [Price/unit], [Total]) values (@CN,@CD,@PN,@D1)"
Dim con1 As New SqlClient.SqlConnection(ConnectionString)
Dim cmdInsert As New SqlClient.SqlCommand(strInsert, con1)
con1.Open()
For Each DGR As DataGridViewRow In _111DataGridView.Rows
If Not DGR.IsNewRow Then
pid = DGR.Cells(0).Value.ToString()
name = DGR.Cells(1).Value.ToString()
qty = DGR.Cells(2).Value.ToString()
cp = DGR.Cells(3).Value.ToString()
With cmdInsert
.Parameters.Clear()
.Parameters.AddWithValue("@CN", pid)
.Parameters.AddWithValue("@CD", name)
.Parameters.AddWithValue("@PN", qty)
.Parameters.AddWithValue("@D1", cp)
.ExecuteNonQuery()
End With
End If
Next
Please help