How to read NULL values in SQL using VB .net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear folks,
I have a column of data in MS SQL that is being read by my VB .net program. There are a couple of blank/NULL data in those columns. How do I read that data as NULL in VB .net and then make the program skip it. Any pointers would be appreciated.

cheers,

Ranjan
 
Hi,

Here is a quick example.

Dim strConn As String
Dim conn As OleDb.OleDbConnection
Dim daCustomer As OleDb.OleDbDataAdapter
Dim ds As DataSet

ds = New DataSet()
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDb.OleDbConnection(strConn)

daCustomer = New OleDb.OleDbDataAdapter("Select * from Customers",
conn)

ds = New DataSet

daCustomer.Fill(ds, "Customers")

For intRow As Integer = 0 To ds.Tables("Customers").Rows.Count - 1
Dim dr As DataRow = ds.Tables("Customers").Rows(intRow)
For x As Integer = 0 To ds.Tables("Customers").Columns.Count - 1
If Not dr.IsNull(x) Then
Debug.WriteLine(dr.Item(x))
Else
Debug.WriteLine("Null")
End If
Next
Next

Ken
 
Back
Top