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?
 
Ashish PatelConnect With a Mentor Commented:
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
 
patelajkAuthor Commented:
bingo.... thanks
0
All Courses

From novice to tech pro — start learning today.