Making a field null
-
Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron
-
Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron
-
Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron
Instead of
null
, useSystem.DBNull.Value
. This is because in certain cases you will need to distinguish between a C#null
and a database null. For example, in the case ofExecuteScalar
anull
result means that there was no result (i.e. the answer did not exist) whereas ifExecuteScalar
returnsDBNull.Value
then the answer from the database is null (i.e. there is an answer, and the answer is null). See MSDN: System.DBNull[^] Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog
-
try this myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = ""; dadax_85@hotmail.com
That won't work either. An empty
string
is notnull
, it is astring
of zero length.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog
-
Instead of
null
, useSystem.DBNull.Value
. This is because in certain cases you will need to distinguish between a C#null
and a database null. For example, in the case ofExecuteScalar
anull
result means that there was no result (i.e. the answer did not exist) whereas ifExecuteScalar
returnsDBNull.Value
then the answer from the database is null (i.e. there is an answer, and the answer is null). See MSDN: System.DBNull[^] Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog
I tip my hat to you Colin, thanks!!! I have another issue with changing the field to DBNull... but I think this is a C# issue with binding textbox with DataTable and so I'll post it there as well. I'm not able to: if (txb_Number.Text == "") { //this never occurs because the textbox reverts to the original bound Long Integer value } I can only change the bound data if a new number is used. A blank textbox (or letters entered) only reverts back to the origninal value. I want to update the field to DBNull if the textbox is empty. Ron
-
Hi, I'm working with a Win Form and MS Access. How can I update a field that is a LongInteger to NULL after it has been set with a value? Yes, the db column is set to accept null. This of course did not work :o) myCommand.Parameters.Add("@Number", OleDbType.BigInt).Value = null; Thanks, Ron