DBNull in Tpyed Datasets
-
Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt
-
Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt
I'm not quite sure I understand your question, but if I understand correctly,
DBNull.Value
, will give you a null value you can pass.I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
-
I'm not quite sure I understand your question, but if I understand correctly,
DBNull.Value
, will give you a null value you can pass.I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
hi, thx for u'r response. (i rather be polite thinking you're invention maybe exists. :-) ) Its a column from a typed dataset, which has no value entered by the user. so the value is DBnull. When getting my value to pass to a stored proc it results in an error. Typed dataset DataSet1 with Table1 has 3 columns all integers with property allow DBnull Gives a row Table1Row with fields Table1Row.ID1, Table1Row.ID2, Table1Row.ID3 when calling for example Table1Row.ID2 it gives an error. In designtime the property Nullvalue also remains (throw exception) and cannot be modified. For string fields it's no problem. Thx again. :-) Kurt
-
hi, thx for u'r response. (i rather be polite thinking you're invention maybe exists. :-) ) Its a column from a typed dataset, which has no value entered by the user. so the value is DBnull. When getting my value to pass to a stored proc it results in an error. Typed dataset DataSet1 with Table1 has 3 columns all integers with property allow DBnull Gives a row Table1Row with fields Table1Row.ID1, Table1Row.ID2, Table1Row.ID3 when calling for example Table1Row.ID2 it gives an error. In designtime the property Nullvalue also remains (throw exception) and cannot be modified. For string fields it's no problem. Thx again. :-) Kurt
topcatalpha wrote:
thx for u'r response. (i rather be polite thinking you're invention maybe exists. )
:laugh:
topcatalpha wrote:
When getting my value to pass to a stored proc it results in an error.
What is the error message you are recieving?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
-
topcatalpha wrote:
thx for u'r response. (i rather be polite thinking you're invention maybe exists. )
:laugh:
topcatalpha wrote:
When getting my value to pass to a stored proc it results in an error.
What is the error message you are recieving?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
The error message is : The value for column 'ID2' in table 'Table1' is DBNull
-
The error message is : The value for column 'ID2' in table 'Table1' is DBNull
Double check that the field ID2 does allow null values, that make sure that there isn't a exception thrown if there is a null value. Additionally, in your code, you can check the value before passing it, and if it is equal to DBNull then set the value to 0 instead of null.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
-
Double check that the field ID2 does allow null values, that make sure that there isn't a exception thrown if there is a null value. Additionally, in your code, you can check the value before passing it, and if it is equal to DBNull then set the value to 0 instead of null.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
Found something : [^] i need to check each field for null and pass null value myself. Seems very unlogic to me knowning that SQL servers allow DBnull values in tables. Ex :
if(Table1Row.IsID2Null()) ATDatabase.AddInParameter(updateCommand, "ID2", DbType.Int32, null); else ATDatabase.AddInParameter(updateCommand, "ID2", DbType.Int32, Table1Row.ID2);
Checking the auto generated code from the typed dataset:[System.Diagnostics.DebuggerNonUserCodeAttribute()] public long ID2 { get { try { return ((long)(this[this.Table1.ID2Column])); } catch (System.InvalidCastException e) { throw new System.Data.StrongTypingException("The value for column \'ID2\' in table \'Table1\' is DBNull.", e); } } set { this[this.Table1.ID2Column] = value; } }
Cannot pass null value here... greetz Kurt -
Hi, Does anyone know how the get/Pass the DBnull Value of an integer field from a typed dataset without getting an error? Propertie Allow DBnull is true for my integer field. Thx Kurt