The parameterized query ..... expects the parameter '@units', which was not supplied
Try this code:
SqlParameter unitsParam = command.Parameters.AddWithValue("@units", units);
if (units == null)
{
unitsParam.Value = DBNull.Value;
}
And you must check all other parameters for null value. If it null you must pass DBNull.Value
value.
The parameterized query expects the parameter which was not supplied
If you pass null value to parameter,you will get this error even after you add the parameter
so try to check the value and if it null then use DBNull.Value
This will work
cmd.Parameters.Add("@Department", SqlDbType.VarChar)
If (TextBox2.Text = Nothing) Then
cmd.Parameters("@Department").Value = DBNull.Value
Else
cmd.Parameters("@Department").Value = TextBox2.Text
End If
This will convert the null values from the object layer to DBNull values that are acceptable to the database.
The parameterized query expects the parameter '@Id', which was not supplied
cmd.Parameters.Add("@Id",SqlDbType.Int);
You are Adding a parameter, but you are not giving a value for it. Because of that you are receiving this error.
If the ID column is Auto Incremented just remove it from the Stored Procedure.
EDIT: If you don't know how to create the column auto incremented check this answer:
Auto increment primary key in SQL Server Management Studio 2012
The parameterized query expects the parameter , which was not supplied
public void insertAddress(AddressModel address)
{
var connection = OpenConnection();
var command = connection.CreateCommand();
command.CommandText = "insert into Adres (AddressLine_1,AddressLine_2,Postcode,Town,DateMovedIn,Id) values (@AddressLine_1, @AddressLine_2, @Postcode, @Town,@DateMovedIn,@Id)";
command.Parameters.Add(new SqlParameter { ParameterName = "@AddressLine_1", Value = address.AddressLine_1 });
if (address.AddressLine_2 == null)
{
command.Parameters.Add(new SqlParameter { ParameterName = "@AddressLine_2", Value = DBNull.Value });
}
else
{
command.Parameters.Add(new SqlParameter { ParameterName = "@AddressLine_2", Value = address.AddressLine_2 });
}
command.Parameters.Add(new SqlParameter { ParameterName = "@Postcode", Value = address.Postcode });
command.Parameters.Add(new SqlParameter { ParameterName = "@Town", Value = address.Town });
command.Parameters.Add(new SqlParameter { ParameterName = "@DateMovedIn", Value = address.DateMovedIn.ToString("yyyyMMdd") });
command.Parameters.Add(new SqlParameter { ParameterName = "@Id", Value = address.Id });
command.ExecuteNonQuery();
}
The parameterized query expects the parameter p1 which was not supplied
"For some reason when I pass 0, it is converted to BigInt. I do not know why.
I parsed 0 to int and it worked.
using (var context = new DbContext())
{
context.Database.ExecuteSqlCommand(
@"EXEC dbo.MyProc @p1, @p2, @p3, @p4, @p5, @p6, @p7",
new SqlParameter("p1", int.Parse("0"),
new SqlParameter("p2", myDate),
new SqlParameter("p3", DBNull.Value),
new SqlParameter("p4", DBNull.Value),
new SqlParameter("p5", myValue),
new SqlParameter("p6", int.Parse("0")),
new SqlParameter("p7", DBNull.Value));
}
The parameterized query expects the parameter which was not supplied where the value is not null
Your CommandText
parameters do not match the actual parameters as seen in the error message. The actual query thinks has @item
but your example has @item1
. Likewise, @q1
is not @quantity
.
I don't think the code you have shown is in context, you are not using the command text that you think you are.
Related Topics
SQL Multiple Columns in In Clause
Concatenate Results from a SQL Query in Oracle
How to Do a Max(Count(*)) in SQL
The Parameterized Query Expects the Parameter Which Was Not Supplied
Extract Date (Yyyy/Mm/Dd) from a Timestamp in Postgresql
Get Next Sequence Value from Database Using Hibernate
SQL Pivot and String Concatenation Aggregate
Dynamic Pivot Table in SQL Server
How to Kill a Running Select Statement
Generate All Combinations in SQL
Why Are Relational Set-Based Queries Better Than Cursors
SQL Server Date Format Function
Which SQL Query Is Better, Match Against or Like
How to Declare Global Variable in SQL Server..
What Datatype to Use When Storing Latitude and Longitude Data in SQL Databases
Aggregate Function in SQL Where-Clause