Question How can I add row to empty dataset

savoym

Member
Joined
Feb 10, 2009
Messages
6
Programming Experience
3-5
After I submitted my query I got an empty dataset. A populated dataset brings back 2 columns and I want to add data to an empty dataset. I am a newbie to VB.net. I've inherited this vb.net windows app and need to account for an empty dataset and populate the 2 columns appropriate when no data is returned.

I want to populate a NULL value in the first column and a string value in the 2nd column of this dataset. I just don't know how to populate this dataset and needing some help/direction.

I tested to see if the dataset was empty by using the following after googling and finding the DataRow class but I'm having problems:

VB.NET:
If odataset.Tables(0).Rows.Count() > 0 Then
     allDataGrid.DataSource = odataset.Tables(0)
     allDataGrid.DataBind()  -- WORKS GREAT!!
Else
     Dim drow As DataRow
     Dim value1 As String
     Dim value2 As String
     value1 = ""
     value2 = "No records found"
     drow.ItemArray[value1, value2]
     odataset.Tables(0).Rows.Add(drow)
     allDataGrid.DataSource = odataset.Tables(0)
     allDataGrid.DataBind()
End If

The ELSE part of my code above is NOT working. Again any help or direction would be appreciated. I'm sure I'm missing something simple but just don't know what.

:confused:
 
Last edited:
I tried the following and I'm getting an unhandled NULL exception:

VB.NET:
            Dim drow As DataRow
            drow(0) = "None"
            drow(1) = "No CPT codes found in the 70000-89999 range that match"
            odataset.Tables(0).Rows.Add(drow)
            allCPTGrid.DataSource = odataset.Tables(0)
            allCPTGrid.DataBind()

Again, any suggestions or direction would be greatly appreciated. Thanks.
 
I resolved my problem. The following is what I did:

VB.NET:
            Dim drow As DataRow = odataset.Tables(0).NewRow
            drow(0) = "None"
            drow(1) = "No CPT codes found in the 70000-89999 range that match your filter description value above"
            odataset.Tables(0).Rows.Add(drow)
            allCPTGrid.DataSource = odataset.Tables(0)
            allCPTGrid.DataBind()
 
Back
Top