john cenator
john cenator

Reputation: 33

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?

Upvotes: 0

Views: 3600

Answers (1)

Ivan Stoev
Ivan Stoev

Reputation: 205569

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);

Upvotes: 1

Related Questions