Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > How to find a NULL in a dataset ?
 

How to find a NULL in a dataset ?

Dim sqlStr As String = "SELECT * FROM urlTable WHERE urlName='" & CStr(comboSearch.SelectedItem) & "'"

Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)

dataAdapter.Fill(dt)

dataAdapter.Dispose()

I have declared all the neccessary variblas and the code is working fine

Now lets say i give this command...

urlStart =
CStr(dt.Rows(0)("urlStart"))

Now the code will work fine when there is a value in urlStart...but will generate an error when it is NULL...

what is the command where i can find whether urlStart has a NULL value and if not only run the above command?

Im looking for a valid code something like

If dt.Rows(0)("urlStart") <> NULL Then
urlStart = CStr(dt.Rows(0)("urlStart"))
Else
urlStart = ""
End if

What i want is how to find whether it is NULL or not without first??

I get this warning too...
Warning1 :Variable 'urlStart' is used before it has been assigned a value. A null reference exception could result at runtime.

Thanx a lot :D

  • Edited byRanhiru123 Tuesday, June 24, 2008 1:40 PMAdded information
  • Changed TypeRanhiru123 Tuesday, June 24, 2008 1:38 PMMy fault :D
  • Edited byRanhiru123 Tuesday, June 24, 2008 1:41 PMAdded information
  •  
Ranhiru123  Tuesday, June 24, 2008 1:36 PM

Research DBNull. This is a sample from VB Help. But in general, you may be going into the wrong direction with your implimentation.

If you can create a typed dataset, do so.

Add a select qry to the data adapter.Then you can access like so:

MyDataAdapter.GetByCustomerId("C123456")

Otherwise, This gets ugly
"CStr(dt.Rows(0)("urlStart"))"

on the other hand you can reference like so:

MyCurrentRow.urlstart = "somevalue"




PrivateSubOUtputLabels(dtAsDataTable)
DimlabelAsString
'Iteraterowsoftable
ForEachrowAsDataRowIndt.Rows
DimlabelLenAsInteger
label=String.Empty
label+=AddFieldValue(label,row,"Title")
label+=AddFieldValue(label,row,"FirstName")
label+=AddFieldValue(label,row,"MiddleInitial")
label+=AddFieldValue(label,row,"LastName")
label+=AddFieldValue(label,row,"Suffix")
label+=vbCrLf
label+=AddFieldValue(label,row,"Address1")
label+=AddFieldValue(label,row,"AptNo")
label+=vbCrLf
labelLen=Len(label)
label+=AddFieldValue(label,row,"Address2")
IfLen(label)<>labelLenThenlabel+=vbCrLf
label+=AddFieldValue(label,row,"City")
label+=AddFieldValue(label,row,"State")
label+=AddFieldValue(label,row,"Zip")
Console.WriteLine(label)
Console.WriteLine()
Next
EndSub
PrivateFunctionAddFieldValue(labelAsString,rowAsDataRow,_
fieldNameAsString)AsString
IfNotDbNull.Value.Equals(row.Item(fieldName))Then
ReturnCStr(row.Item(fieldName))&""
Else
ReturnNothing
EndIf
EndFunction
DaveKlem  Wednesday, July 02, 2008 7:23 AM
This question has nothing to do with either GAX or GAT, please post it to a more appropiate forum.

thanks,
-vga.
Working with GAX/GAT/DSL? Download SFT now! http://softwarefactoriestoolkit.net
  • Proposed As Answer byvga Thursday, July 03, 2008 2:08 AM
  •  
vga  Thursday, July 03, 2008 2:08 AM

You can use google to search for other answers

Custom Search

More Threads

• Problem Loading Package
• *.vstemplate for and *.csproj/*.vbproj must be kept in sync.
• Share arguments between recipes
• Update project references accross solution.
• Unsupported version of Microsoft Visual C# 3.0 / Microsoft Visual Basic 9.0
• Problems installing SCSF source code may 2007
• Problem with GAT not loading templates properly
• Advice needed: What technology/kit/etc to use when porting exsisting VS wizards
• Command Bar to Bound recipe
• Unable to add reference to project