|
-
Jul 8th, 2002, 06:15 AM
#1
Thread Starter
Addicted Member
DBNull data type to string
I created a DataSet fro a query and populate a table with its values. But when a field contains NULL value I receive an error message about conversion DBNull data type to string. Can anyone help me how to solve this problem?
The code as follows:
ByVal strTableName As String)
Dim r As TableRow
Dim c As TableCell
Dim myTable As DataTable
Dim myRow As DataRow
Dim myColumn As DataColumn
Dim strTemp As String
' For each table in the DataSet, print the row values.
myTable = myDataSet.Tables(strTableName)
For Each myRow In myTable.Rows
r = New TableRow()
For Each myColumn In myTable.Columns
c = New TableCell()
strTemp = myRow(myColumn)
c.Controls.Add(New LiteralControl(strTemp))
r.Cells.Add(c)
Next myColumn
Table1.Rows.Add(r)
Next myRow
End Sub
-
Jul 8th, 2002, 03:02 PM
#2
Fanatic Member
Re: DBNull data type to string
Originally posted by bona
I created a DataSet fro a query and populate a table with its values. But when a field contains NULL value I receive an error message about conversion DBNull data type to string. Can anyone help me how to solve this problem?
The code as follows:
.
.
.
strTemp = myRow(myColumn)
.
.
.
I only have a C# version, but you should be able to see the direction to go.
Code:
.
.
.
strTemp = CheckNull(myRow(myColumn))
.
.
.
private String CheckNull(Object objIn)
{
string strRetVal;
if (objIn == DBNull.Value) {
strRetVal = "";
}
else {
strRetVal = objIn.ToString();
}
return strRetVal;
}
-
Jul 9th, 2002, 04:54 AM
#3
Thread Starter
Addicted Member
Thanks, Patoooey.
It works excellent, the VB code:
...
strTemp = CheckNull(myRow(myColumn))
...
Private Function CheckNull(ByVal objIn As Object) As String
Dim strRetVal As String
If (objIn Is DBNull.Value) Then
strRetVal = ""
Else
strRetVal = objIn.ToString()
End If
Return strRetVal
End Function
Last edited by bona; Jul 9th, 2002 at 05:01 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|