Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In dtissue.Rows
'Provider=SQLOLEDB;Data Source=ERPSERVER;Password=tum;User ID=sa;Initial Catalog=nyrubber1
Dim constring As String = "Data Source=ERPSERVER;Password=tum;User ID=sa;Initial Catalog=nyrubber1"
Using con As New SqlConnection(constring)
Using cmd As New SqlCommand("INSERT INTO pnissue VALUES(@pncode, @pndry)", con)
cmd.Parameters.AddWithValue("@pncode", row.Cells(0).Value)
cmd.Parameters.AddWithValue("@pndry", row.Cells(1).Value)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Next
MessageBox.Show("Records inserted.")
มันขึ้น error ครับ
Prepared statement '(@pncode nvarchar(4000),@pndry nvarchar(4000))INSERT INTO pnissu' expects parameter @pncode, which was not supplied.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Con As OleDbConnection = New OleDbConnection
Dim constring As String = "Data Source=ERPSERVER;Password=tum;User ID=sa;Initial Catalog=nyrubber1"
Dim Com As OleDbCommand
Dim pntruckno As String
Dim pnitemname As String
Dim pnunitcode As String
Dim str1 As String
Com = New OleDbCommand
Com.Connection = Con
For x As Integer = 0 To PNrubberDataGridView.Rows.Count - 1
pntruckno = PNrubberDataGridView.Rows(x).Cells(0).Value
pnitemname = PNrubberDataGridView.Rows(x).Cells(1).Value
pnunitcode = PNrubberDataGridView.Rows(x).Cells(2).Value
STR1 = "INSERT INTO pnissue() VALUES (@pntruckno, @pnitemname, @pnunitcode)"
Dim Comm As New OleDbCommand(STR1, Con)
Comm.Parameters.AddWithValue("@pnissue", pntruckno)
Comm.Parameters.AddWithValue("@Sales_Date", pnitemname)
Comm.Parameters.AddWithValue("@Copies", pnunitcode)
Comm.Dispose()
Next
MessageBox.Show("บันทึกข้อมูลแล้ว")
End Sub