Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im trying to insert records into an SQL table through VB.Net.
The Records are inserted but I get the following Error Message:
The parameterized query '(@EmpName varchar(8000),@USDBasic money,@OtherUSDEarnings money,' expects the parameter '@EmpName', which was not supplied.


What I have tried:

I have tried to cater for Null values through this code ,but to no avail.
If @EmpName = Nothing Then
cmd.Parameters.Add("@EmpName", SqlDbType.VarChar).Value = BDNull.value
Else
cmd.Parameters.Add("@EmpName", SqlDbType.VarChar).Value = DataGridView1.Rows(i).Cells(0).Value
Posted
Updated 5-Feb-23 19:07pm
Comments
Dave Kreskowiak 5-Feb-23 23:12pm    
Need to see the code, including the setup of the query and parameters.
Sandeep Mewara 5-Feb-23 23:14pm    
2 things:
1. Believe it's a typo and it's DBNull and not BDNull
2. You want to change the if condition. A quick debug might help to assure.

// check for valid value before using for comparison
If DataGridView1.Rows(i).Cells(0).Value = Nothing Then
cmd.Parameters.Add("@EmpName", SqlDbType.VarChar).Value = BDNull.value
Else
cmd.Parameters.Add("@EmpName", SqlDbType.VarChar).Value = DataGridView1.Rows(i).Cells(0).Value

1 solution

Ignoring that the VB code won't even compile ...

Look at the error message:
Error
The parameterized query '(@EmpName varchar(8000),@USDBasic money,@OtherUSDEarnings money,' expects the parameter '@EmpName', which was not supplied.
That is pretty explicit, and for an SQL error message it is pretty clear: it means that the EmpName you supplied was a NULL value, and the SP is set up specifically not to accept nulls. YOu could change the SP to allow nulls, but a better solution is to prevent the INSERT from happening at all if there is no such data.

We can't help you fix that - it's a design decision you need to take and which is very relevant to your DB design that we have no access to!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900