Sir,
When i tried to insert data from datagridview to my sql database table named "GenPaySlip", it throws an error:- Must declare the scalar variable @GID.
Can anyone suggest me how to solve this error....
What I have tried:
Below is my code for inserting data...
Dim oldb_cmd As OleDbCommand
Dim gp_id, fid, wkhr As Integer
Dim phpy, tdpy As Decimal
Dim dtpt As String
con.Open()
oldb_cmd = New OleDbCommand("INSERT INTO GenPaySlip(GPS_Id, Fac_Id, WrkHrs, DtPsnt,PrHrPay, TotDayPay) VALUES (@GID, @FID, @WHR, @DPT, @PHP, @TDP)", con)
Try
For i As Integer = 0 To DgvGPaySlip.Rows.Count - 1
gp_id = gps_id
fid = DgvGPaySlip.Rows(i).Cells(0).Value
wkhr = DgvGPaySlip.Rows(i).Cells(2).Value
dtpt = DgvGPaySlip.Rows(i).Cells(3).Value
phpy = DgvGPaySlip.Rows(i).Cells(4).Value
tdpy = DgvGPaySlip.Rows(i).Cells(5).Value
oldb_cmd.Parameters.AddWithValue("@GID", gp_id)
oldb_cmd.Parameters.AddWithValue("@FID", fid)
oldb_cmd.Parameters.AddWithValue("@WHR", wkhr)
oldb_cmd.Parameters.AddWithValue("@DPT", dtpt)
oldb_cmd.Parameters.AddWithValue("@PHP", phpy)
oldb_cmd.Parameters.AddWithValue("@TDP", tdpy)
oldb_cmd.ExecuteNonQuery()
oldb_cmd.Parameters.Clear()
Next
Catch ex As Exception
Beep()
MsgBox(ex.Message, MsgBoxStyle.Information, "Information")
End Try
con.Close()
MessageBox.Show("All Data Inserted")
Sql Table Description:-
GPS_Id int Unchecked
Fac_Id int Checked
WrkHrs int Checked
DtPsnt varchar(15) Checked
PrHrPay decimal(18, 2) Checked
TotDayPay decimal(18, 2) Checked
Unchecked