Here is what I used when I needed to have zero-length strings instead of NULL in a Dataset. It also deletes a row if it consists entirely NULL Strings.
Public Shared Sub _
SetIsNullStringsToEmpty( _
ByVal DataSet As DataSet)
' Set every Type(string) Item that ISnull to String.Empty
Dim dt As DataTable
Dim dc As DataColumn
Dim dr As DataRow
Dim I, J, K As Integer
Dim blnAllNull As Boolean
Dim sName As String = String.Empty
For I = 0 To DataSet.Tables.Count - 1
dt = DataSet.Tables(I)
' Go Backwards for RemoveAt
For J = dt.Rows.Count - 1 To 0 Step -1
dr = dt.Rows(J)
blnAllNull = True
For K = 0 To dr.Table.Columns.Count - 1
' Get Coulumn
dc = dr.Table.Columns(K)
sName = dc.ColumnName
If dc.DataType Is GetType(String) Then
If dr.IsNull(dc.Ordinal) Then
dr.Item(dc.Ordinal) = String.Empty
Else
blnAllNull = False
End If
Else
blnAllNull = False
End If
Next
If blnAllNull Then
dr.Table.Rows.Remove(dr)
End If
Next
Next
End Sub
Dim ts As New DataGridTableStyle()
ts.MappingName = "nameOfTheTableInDatasetWitchGridUsesAsDataSource"
Me.grddate.TableStyles.Clear()
Me.grddate.TableStyles.Add(ts)
ts.GridColumnStyles("ColumnName".NullText = " "
in column ColumnName it puts " " instead of null
Cool. Too bad there isn't one for the DataColumn. I get my data returned as XML from a BizTalk server, put it into a strongly typed DataSet with the ReadXML method and process from there.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.