I wanted to check for an empty dataset which is being returned from a datagrid. How can I do that
Dim myDataSet As DataSet
' this code returns the dataset of datagrid dgmonth.
myDataSet = CType(dgmonth.DataSource, DataSet)
so I wanted to write
if myDataSet = nothing then
exit sub
end if
but this if..then loop gives an error. I will appreciate any help. Thanks

How can I check for Null dataset
Jerrycee11
Try
If myDataset.Tables(0).Rows.Count = 0 Then
messagebox.show("Dataset Empty")
Else
messagebox.show("Dataset Not Empty")
End If
Catch
'handle error here
End Try
This assumes there's a single table in your myDataSet. You can specify the table name if there are more. E.g
If myDataset.Tables("TableName").Rows.Count = 0 Then
Else
End If
zatom idham
Jody
Sanjoy Debnath
sboots
Jaqq
ImCampos
but because you are databinding, I'll let it slide.
You might want to try <a href="http://www.asp.net">www.asp.net</a> for more response
NemosNemos
Dim strSQL as String = "SELECT * FROM database"
Dim objAdapter as new OledbDataAdapter(strSQL, objConnection)
Dim objDataSet as new DataSet()
objAdapter.Fill(objDataSet, "name")
Dim objDataView as new DataView(objDataSet.Tables("Balisong"))
dgbalisong.DataSource = objDataView
dgbalisong.DataBind()
I am somewhat new to ASP.NET and I appreciate any help anyone can provide.
Cortex
I have an Access database with items from a collection stored in it. Each item has a "status" field which I assign one of four classifications. The datagrid displays the items in a specific catagory based on a drop down list selection. Sometimes there won't be anything in a specific catagory like "For Sale" and I don't want to show a datagrid header with nothing in the datagrid (this is what my page is doing now). I am coding everything by hand; I don't use VS.NET. Last time around, I had the aspx page and a code behind page. This time around, I put all the database code in a namespace, compiled it and my code behind page handles only the events.
Here is my function which is part of a namespace that I have compiled:
Public Function GetBalisongList(strStatus as string, strSort as string) as Dataset
If strStatus = "complete" Then
strSQL = "SELECT BalisongID, make, model, status FROM balisong ORDER BY " & strSort
Else
strSQL = "SELECT BalisongID, make, model, status FROM balisong WHERE status = '" & strStatus & "' ORDER BY " & strSort
End If
Dim objConnection as New OLEDBConnection(m_DSN)
Dim objDataAdapter as New OLEDBDataAdapter(strSQL, objConnection)
Dim BalisongList as new Dataset()
objDataAdapter.Fill(BalisongList)
Return BalisongList
End Function
Here is the sub that handles the drop down list in my code behind page:
Public Sub balisongfilter(sender as object, e as eventargs)
ViewState("status") = ddl_balisong.SelectedItem.Value
If ViewState("status") = "description" Or ViewState("status") = "" Then
lblinstructions.visible = true
dgBalisongList.visible = false
rptBalisongDetails.visible = false
Else
strSort = "make, model"
Dim BalisongStatusList as new Balisong(strconnect)
dgBalisongList.DataSource = BalisongStatusList.GetBalisongList(ViewState("status"), strSort)
dgBalisongList.DataBind()
lblinstructions.visible = false
dgbalisonglist.visible = true
rptBalisongDetails.visible = false
End If
End Sub
If there are not any items with a specific status then I want to display an asp:label saying something like, "I do not currently have any balisongs for sale." instead of an empty datagrid. Would I check for an empty dataset in my fuction or in the event handling sub What is the best practice for doing this Thank you in advance for any help you can provide.
Bjorn Coltof
If myDataSet Is Nothing then
Exit Sub
End If
Don't ask me why but if I use IS as opposed to =, I get my result...
Byrd Man
shadownnc
Dim strSQL as String = "SELECT * FROM database"
Dim objAdapter as new OledbDataAdapter(strSQL, objConnection)
Dim objDataSet as new DataSet()
objAdapter.Fill(objDataSet, "name")
Case 1:
if objDataSet.Tables("Balisong") is nothing then
Exit sub
Else
Dim objDataView as new DataView(objDataSet.Tables("Balisong"))
dgbalisong.DataSource = objDataView
dgbalisong.DataBind()
End if
Case 2
if objDataSet.Tables("Balisong").rows.count <=0 then
Exit sub
Else
Dim objDataView as new DataView(objDataSet.Tables("Balisong"))
dgbalisong.DataSource = objDataView
dgbalisong.DataBind()
End if
hope this will help u.....................
Regards,
Ritesh