Search code examples
c#databaseoledbparameter

OleDBParameterCollection only accepts non null values OleDbparmeter type objects


 lala.Parameters.Add(new OleDbParameter("@Base", OleDbType.SmallInt).Value = textBox15.Text);
 textBox15.Text = reader["@Base"].ToString();

The following error occurs in the first line of code

OleDBParameterCollection only accepts non null values OleDbparmeter type objects

Any suggestions?


Solution

  • new OleDbParameter("@Base", OleDbType.SmallInt).Value = textBox15.Text is an assignment expression of type string. So lala.Parameters.Add(new OleDbParameter("@Base", OleDbType.SmallInt).Value = textBox15.Text); actually is calling OleDbParameterCollection.Add Method (Object) (https://msdn.microsoft.com/en-us/library/ms136047(v=vs.110).aspx). And obviously string is not a OleDbParameter object.

    The correct way is to use local variable:

    var parameter = new OleDbParameter("@Base", OleDbType.SmallInt);
    parameter.Value = textBox15.Text;
    lala.Parameters.Add(parameter);