sql - How do I insert records that have int fields with no values? -


Assuming that I have this access table with a text field and 4 number fields, here is the relevant code:

  New OleDb.OleDbCommand cmd.Connection = Thief cmd.CommandType = CommandType.Text cmd.CommandText = "Insert in Table1" as the dim cmd _ & amp; "Values ​​(?,?,?,?,?)" Cmd.Parameters.AddWithValue ("@ a", a.Text) cmd.Parameters.AddWithValue ("@b", CInt (b.Text)) cmd.Parameters .AddWithValue ("@ c", CInt (c.Text)) cmd.Parameters.AddWithValue ("@ d", CInt (d.Text)) cmd.Parameters.AddWithValue ("@E", CInt (e.Text) ) Ole.InsertCommand = cmd ole.InsertCommand.ExecuteNonQuery () ds.Clear () ole.Fill (ds)  

This works fine at first, but when I have no Leave a number field and value it, it gives this: "Criteria expression mismatch the data type" How do I work around this?

You do not need to convert values ​​to an integer. She said, should work using the given function. Use this as follows: cmd.Parameters.AddWithValue ("@b", ValueOrNull (b.Text))

  public function ValueOrNull (ByVal obj object) as the object if NB nothing obj OrElse obj DBNull.Value OrElse String.IsNullOrEmpty (obJ.ToString) After this return DBNull.Value or else return obj end is the end function  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -