F
Fox
Cannot accept null value in parameter list
My SQL Server can accept null value on field CustomerName
When I run this example
SqlConnection nwindConn = new SqlConnection("Data Source=(local);Integrated
Security=SSPI;Initial Catalog=northwind");
SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CustomerName
FROM Customer", nwindConn);
nwindConn.Open();
SqlCommand insertCMD = new SqlCommand("insert into
Customer(CustomerID,CustomerName) values
(@CustomerID,@CustomerName)",nwindConn);
insertCMD.Parameters.Add("@CustomerID",SqlDbType.Int);
insertCMD.Parameters.Add("@CustomerName",SqlDbType.Char,30);
insertCMD.Parameters["@CustomerName"].Value =null;
insertCMD.Parameters["@CustomerID"].Value =15;
try
{
insertCMD.ExecuteNonQuery();
}
catch (Exception em)
{
MessageBox.Show(em.ToString());
}
The error message : expects parameter @CustomerName which was not supplied
My SQL Server can accept null value on field CustomerName
When I run this example
SqlConnection nwindConn = new SqlConnection("Data Source=(local);Integrated
Security=SSPI;Initial Catalog=northwind");
SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CustomerName
FROM Customer", nwindConn);
nwindConn.Open();
SqlCommand insertCMD = new SqlCommand("insert into
Customer(CustomerID,CustomerName) values
(@CustomerID,@CustomerName)",nwindConn);
insertCMD.Parameters.Add("@CustomerID",SqlDbType.Int);
insertCMD.Parameters.Add("@CustomerName",SqlDbType.Char,30);
insertCMD.Parameters["@CustomerName"].Value =null;
insertCMD.Parameters["@CustomerID"].Value =15;
try
{
insertCMD.ExecuteNonQuery();
}
catch (Exception em)
{
MessageBox.Show(em.ToString());
}
The error message : expects parameter @CustomerName which was not supplied