gdbjohnson
asked on
Is it possible to Assign DBNull to a column in a row in a Typed-DataSet?
I have a Strong-Typed DataSet, and even though a column can accept a null in my SQL Database, I am having a bit of trouble finding how I might assign a column to DBNull in code, rather than some default value.
I almost want to override my
<DataSet>.<Table>.Add<Tabl e>Row()
method with one that excludes a column, or allows me to enter a DBNull for it, instead of, say, an int.
Is it possible?
g
I almost want to override my
<DataSet>.<Table>.Add<Tabl
method with one that excludes a column, or allows me to enter a DBNull for it, instead of, say, an int.
Is it possible?
g
this would be on a datarow object.
The problem is that a int column cannot have a dbnull value. What u can do is instead of sending null values from the database for this column send 0
Or write a function
public int IntValue(Object 0)
{
if( (o == null) || (o==dbnull.value))
{
return Convert.ToInt32(null);
}
else
{
return Convert.ToInt32(o);
}
}
Before u databind the datagrid
for(int i = 0;i<=rowcount;i++)
{
datatable.Rows(i)(intColum n) = IntValue(datatable.Rows(i) (intColumn )); //Pass this column value through the IntValue function
}
public int IntValue(Object 0)
{
if( (o == null) || (o==dbnull.value))
{
return Convert.ToInt32(null);
}
else
{
return Convert.ToInt32(o);
}
}
Before u databind the datagrid
for(int i = 0;i<=rowcount;i++)
{
datatable.Rows(i)(intColum
}
An int column can have a dbnull value and you should be able to call the SetMyIntValueNull() function.
ASKER
but what about the initial row creation part. I know how to test for DBNull, but my problem is when I first create a new row in the dataset:
the method is:
ds.MyTable.AddMyTableRow(i nt col1, int col2, int col3)
My problem is that I don't have a value to set for col3. How do I add a row to the dataset so that col3 == DBNull.
Are you saying to assign it an int initially, and then set it to DBNull after the row is added?
-g
the method is:
ds.MyTable.AddMyTableRow(i
My problem is that I don't have a value to set for col3. How do I add a row to the dataset so that col3 == DBNull.
Are you saying to assign it an int initially, and then set it to DBNull after the row is added?
-g
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
haha.. ok. I knew it was something easy.
g
g
glad to help... good luck
for instance...
SetPhoneNumberNull();
unless you have declared the column so that it cannot be null
They also have IsPhoneNumberNull();