Empty Dataset

Hi

I have code below which creates a dataset, how do i modify it so that it checks if the dataset is empty and if so then does something.

my if block at the end doesnt seem to work

thanks in advance
Sub bindmaindata()
        ' use the searchterm to find matching results
        Dim sqlStmt As SqlCommand
        Dim spparam As SqlParameter
 
        sqlStmt = New SqlCommand("sp_g_InvestorSearch", objconn)
        sqlStmt.CommandType = CommandType.StoredProcedure
        spparam = sqlStmt.Parameters.Add("@search_text", SqlDbType.VarChar, 60)
        spparam.Direction = ParameterDirection.Input
        If Page.IsPostBack Then
            If fndSearch.Text = "" Then
                spparam.Value = "xxxxxxxxx" 'crap way to do it but prevent empty search term
            Else
                spparam.Value = fndSearch.Text.Replace("'", "''")
            End If
        Else
            spparam.Value = Request.Params("q").Replace("'", "''")
            fndSearch.Text = Request.Params("q")
        End If
        spparam = sqlStmt.Parameters.Add("@search_type", SqlDbType.VarChar, 60)
        spparam.Direction = ParameterDirection.Input
        If Page.IsPostBack Then
            spparam.Value = fndSearchType.SelectedIndex
        Else
            spparam.Value = Request.Params("t")
            fndSearchType.SelectedIndex = Request.Params("t")
        End If
 
        spparam = sqlStmt.Parameters.Add("@region", SqlDbType.VarChar, 10)
        spparam.Direction = ParameterDirection.Input
        spparam.Value = Session("IPRegion")
 
        Dim mySqlDataAdapter As New SqlDataAdapter()
        mySqlDataAdapter.SelectCommand = sqlStmt
 
        Dim myDataSet As New DataSet()
        mySqlDataAdapter.Fill(myDataSet)
 
        fndList.DataSource = myDataSet
        fndList.DataBind()
 
        If myDataSet.Tables.Count = 0 Then
            Label1.Text = "Emptry"
        End If
        
    End Sub

Open in new window

patelajkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
Try this way
Sub bindmaindata()
        ' use the searchterm to find matching results
        Dim sqlStmt As SqlCommand
        Dim spparam As SqlParameter
 
        sqlStmt = New SqlCommand("sp_g_InvestorSearch", objconn)
        sqlStmt.CommandType = CommandType.StoredProcedure
        spparam = sqlStmt.Parameters.Add("@search_text", SqlDbType.VarChar, 60)
        spparam.Direction = ParameterDirection.Input
        If Page.IsPostBack Then
            If fndSearch.Text = "" Then
                spparam.Value = "xxxxxxxxx" 'crap way to do it but prevent empty search term
            Else
                spparam.Value = fndSearch.Text.Replace("'", "''")
            End If
        Else
            spparam.Value = Request.Params("q").Replace("'", "''")
            fndSearch.Text = Request.Params("q")
        End If
        spparam = sqlStmt.Parameters.Add("@search_type", SqlDbType.VarChar, 60)
        spparam.Direction = ParameterDirection.Input
        If Page.IsPostBack Then
            spparam.Value = fndSearchType.SelectedIndex
        Else
            spparam.Value = Request.Params("t")
            fndSearchType.SelectedIndex = Request.Params("t")
        End If
 
        spparam = sqlStmt.Parameters.Add("@region", SqlDbType.VarChar, 10)
        spparam.Direction = ParameterDirection.Input
        spparam.Value = Session("IPRegion")
 
        Dim mySqlDataAdapter As New SqlDataAdapter()
        mySqlDataAdapter.SelectCommand = sqlStmt
 
        Dim myDataSet As New DataSet()
        mySqlDataAdapter.Fill(myDataSet)
 
        If myDataSet.Tables.Count = 0 Then
            Label1.Text = "Emptry"
        Else
            fndList.DataSource = myDataSet
            fndList.DataBind()
        End If
        
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
patelajkAuthor Commented:
bingo.... thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.