How to pass a null value to a stored procedure in .NET?

How to pass a null value to a stored procedure in .NET?

Postby mr breaker » Wed 13 Sep 2006 20:51

Hi,

I'm using VS 2005. I can't figure out how to pass a null value as a parameter to a stored procedure.

Ex:

dim da as new DataTableAdapter
da.GetData("Pass a null value here instead of a string")


How can I accomplish this? I've tried passing dbnull.value, dbnull.value.tostring...but I can't get anything to work.


Thanks.
mr breaker
 
Posts: 20
Joined: Thu 31 Aug 2006 18:19

Postby Alexey » Fri 15 Sep 2006 06:42

I can't see any problems in passing DBNull.Value.ToString(). Take a look at the following code:
Code: Select all
WindowsApplication1.DataSet1TableAdapters.test_tinybooleanTableAdapter ta = new WindowsApplication1.DataSet1TableAdapters.test_tinybooleanTableAdapter();
DataTable dt = (DataTable)ta.GetData(DBNull.Value.ToString());

where test_tinybooleanTableAdapter was created using our DataSet Wizard.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby mr breaker » Fri 15 Sep 2006 13:08

Hi,

Thanks for the response. It does work when I pass DBNull.Value.ToString as a parameter to a typed dataset, but only when the column is defined as a string.

If I pass it to a column that is of a different type, such as tinyint or int, then I get this error:

Input string was not in a correct format.
mr breaker
 
Posts: 20
Joined: Thu 31 Aug 2006 18:19

Postby Alexey » Wed 20 Sep 2006 08:46

It seems that null int (or other types) values cannot be passed like that.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby mr breaker » Wed 20 Sep 2006 20:11

Is this a MySQL limitation, or a limitation of the MySQLDirect driver?

I think I've passed null values to integer types with a SQL Server database before.
mr breaker
 
Posts: 20
Joined: Thu 31 Aug 2006 18:19

Postby Alexey » Thu 21 Sep 2006 07:03

VS compiler does not allow to pass DBNull.Value to the function which expects, say, integer value.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL