updating NULL values

  • Thread starter Thread starter Dino M. Buljubasic
  • Start date Start date
D

Dino M. Buljubasic

How can I update fields with a colum as NULL value in VB.net

Something like this:

UPDATE table1
SET colMycolumn = 22
WHERE aCol = NULL

Thank you,
 
Yes I know but I need to write something like:

strQuery = "UPDATE table1 SET col_name = " & intNumber & " WHERE aColumn =
NULL"

.... that is my problem, I have to create an update query string and pass it
to a command and do not know how to do the checking for NULL's in database.

Thank you,
--
Dino Buljubasic
Software Developer
http://rivusglobal.com

Michael Lang said:
Here is how to do with just a simple SQL statement...

SELECT title_id, type, advance
FROM pubs.dbo.titles
WHERE advance IS NULL

or:

SELECT CustomerID, CompanyName, Region
FROM Northwind.dbo.Customers
WHERE Region = NULL

For details see:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/8_qd_06_5.htm
or:
http://doc.ddart.net/mssql/sql2000/html/acdata/ac_8_qd_06_7xir.htm

And here for records already contained inside a DataSet/DataTable...

You can query if a DataRow field has an empty value by...

DataRow dr = ...get row...
if (dr["ColumnName"] == DbNull.Value)
{
//then field is null, do whatever you want with it, such as set as a
new value...
dr["ColumnName"] = ... some new value ...
}

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (a code Generator)
http://sourceforge.net/projects/genadonet (Generic ADO.NET)

Dino M. Buljubasic said:
How can I update fields with a colum as NULL value in VB.net

Something like this:

UPDATE table1
SET colMycolumn = 22
WHERE aCol = NULL

Thank you,
 
You cannot check for NULLs by using =. You have to use
"WHERE aColumn IS Null"

In other words, use "IS Null" instead of "= Null".

Javed

-----Original Message-----
Yes I know but I need to write something like:

strQuery = "UPDATE table1 SET col_name = " & intNumber & " WHERE aColumn =
NULL"

.... that is my problem, I have to create an update query string and pass it
to a command and do not know how to do the checking for NULL's in database.

Thank you,
--
Dino Buljubasic
Software Developer
http://rivusglobal.com

Michael Lang said:
Here is how to do with just a simple SQL statement...

SELECT title_id, type, advance
FROM pubs.dbo.titles
WHERE advance IS NULL

or:

SELECT CustomerID, CompanyName, Region
FROM Northwind.dbo.Customers
WHERE Region = NULL

For details see:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/8
_qd_06_5.htmhttp://doc.ddart.net/mssql/sql2000/html/acdata/ac_8_qd_06_
7xir.htm
And here for records already contained inside a DataSet/DataTable...

You can query if a DataRow field has an empty value by...

DataRow dr = ...get row...
if (dr["ColumnName"] == DbNull.Value)
{
//then field is null, do whatever you want with it, such as set as a
new value...
dr["ColumnName"] = ... some new value ...
}

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (a code Generator)
http://sourceforge.net/projects/genadonet (Generic ADO.NET)

How can I update fields with a colum as NULL value in VB.net

Something like this:

UPDATE table1
SET colMycolumn = 22
WHERE aCol = NULL

Thank you,


.
 
Here is how to do with just a simple SQL statement...

SELECT title_id, type, advance
FROM pubs.dbo.titles
WHERE advance IS NULL

or:

SELECT CustomerID, CompanyName, Region
FROM Northwind.dbo.Customers
WHERE Region = NULL

For details see:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/8_qd_06_5.htm
or:
http://doc.ddart.net/mssql/sql2000/html/acdata/ac_8_qd_06_7xir.htm

And here for records already contained inside a DataSet/DataTable...

You can query if a DataRow field has an empty value by...

DataRow dr = ...get row...
if (dr["ColumnName"] == DbNull.Value)
{
//then field is null, do whatever you want with it, such as set as a
new value...
dr["ColumnName"] = ... some new value ...
}
 
Thank you


You cannot check for NULLs by using =. You have to use
"WHERE aColumn IS Null"

In other words, use "IS Null" instead of "= Null".

Javed

-----Original Message-----
Yes I know but I need to write something like:

strQuery = "UPDATE table1 SET col_name = " & intNumber & " WHERE aColumn =
NULL"

.... that is my problem, I have to create an update query string and pass it
to a command and do not know how to do the checking for NULL's in database.

Thank you,
--
Dino Buljubasic
Software Developer
http://rivusglobal.com

Michael Lang said:
Here is how to do with just a simple SQL statement...

SELECT title_id, type, advance
FROM pubs.dbo.titles
WHERE advance IS NULL

or:

SELECT CustomerID, CompanyName, Region
FROM Northwind.dbo.Customers
WHERE Region = NULL

For details see:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/8
_qd_06_5.htmhttp://doc.ddart.net/mssql/sql2000/html/acdata/ac_8_qd_06_
7xir.htm
And here for records already contained inside a DataSet/DataTable...

You can query if a DataRow field has an empty value by...

DataRow dr = ...get row...
if (dr["ColumnName"] == DbNull.Value)
{
//then field is null, do whatever you want with it, such as set as a
new value...
dr["ColumnName"] = ... some new value ...
}

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (a code Generator)
http://sourceforge.net/projects/genadonet (Generic ADO.NET)

How can I update fields with a colum as NULL value in VB.net

Something like this:

UPDATE table1
SET colMycolumn = 22
WHERE aCol = NULL

Thank you,


.
 
Back
Top