how to send NULL to database?

  • Thread starter Thread starter Bllich
  • Start date Start date
B

Bllich

hy, I have int column 'number' in my table that allowes nulls

when I instance a dataTable in my winform app. and I want to do
table.AddTableRow(string name, int number);
I need to send null value for 'number' to my table. I don't know how..
I tried with Nullable<int> and else .. didn't work.
using sql 2005 express

please help!
thanks.
 
Bllich said:
hy, I have int column 'number' in my table that allowes nulls

when I instance a dataTable in my winform app. and I want to do
table.AddTableRow(string name, int number);
I need to send null value for 'number' to my table. I don't know how..
I tried with Nullable<int> and else .. didn't work.
using sql 2005 express

please help!
thanks.

When they were building the place the workmen didn't want their tools
stolen. For your other question use DBNull.Value
 
PS said:
When they were building the place the workmen didn't want their tools
stolen. For your other question use DBNull.Value

;)

it would be easy if it was a string type column, but this is int type
so I still get an Error - cannot convert from 'System.DBNull' to 'int'.
 
Bllich said:
;)

it would be easy if it was a string type column, but this is int type
so I still get an Error - cannot convert from 'System.DBNull' to 'int'.

I don't use data table that much but the following worked for me

DataTable dt = new DataTable();
dt.Columns.Add("MYIntColumn", typeof(int));
DataRow newRow = dt.NewRow();
newRow[0] = DBNull.Value;
dt.Rows.Add(newRow);
Console.WriteLine(dt.Rows[0].IsNull(0));

PS
 
PS said:
I don't use data table that much but the following worked for me

DataTable dt = new DataTable();
dt.Columns.Add("MYIntColumn", typeof(int));
DataRow newRow = dt.NewRow();
newRow[0] = DBNull.Value;
dt.Rows.Add(newRow);
Console.WriteLine(dt.Rows[0].IsNull(0));

PS

thank you for your reply PS!
 
PS said:
When they were building the place the workmen didn't want their tools
stolen. For your other question use DBNull.Value

What happened before they built the door?

///ark
 
Mark said:
What happened before they built the door?

///ark
Door is the first thing they install.. they actually have some guy hold
it up while they build the frame,then the walls...

<ducking>

P.
 
You can insert Null values(0 for int) in databse for any int, suppose
int column name is Empid

U can declare @Empid as a paramaeter in Stored Procedure
Create procedure PABC
@Empid int,
@name1 varchar(255)
as
INSERT INTO ABC
(Empid,name1)
VALUES (ISNULL(@Empid,''),@name1)

OR

U can also declare parameters in stored procedure like:--

Alter procedure PABC
@Empid int = 0,
@name1 varchar(255) = null
as
INSERT INTO ABC
(Empid,name1)
VALUES (@Empid,@name1)

So here u can go ....... :) :)

Nitin Sharma
(Guru .Net)
 
You can insert Null values(0 for int) in databse for any int, suppose
int column name is Empid

U can declare @Empid as a paramaeter in Stored Procedure
Create procedure PABC
@Empid int,
@name1 varchar(255)
as
INSERT INTO ABC
(Empid,name1)
VALUES (ISNULL(@Empid,''),@name1)

OR

U can also declare parameters in stored procedure like:--

Alter procedure PABC
@Empid int = 0,
@name1 varchar(255) = null
as
INSERT INTO ABC
(Empid,name1)
VALUES (@Empid,@name1)

So here u can go ....... :) :)

Nitin Sharma
(Guru .Net)

nice, thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top