No results.. please try again message
-
Hi there.. :) im workin on a website at the moment in asp.net, using vb.net, in the visual studios 2008 IDE! i just wish to add an extra feature and hopefully someone out there might be able to help. I have a button that reads the values of 5 radio buttons in a radiobutton list, then queries the database, returning results based on the values selected. If no value is returned i wish to display a message saying "No Results this time, please search again" or something to that effect. Im not sure how to do this. here is the code i have behind the button.. Please advise. Protected Sub btnSuggest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSuggest.Click Dim myConnection As SqlConnection Dim myCommand As SqlCommand Dim dr As SqlDataReader Dim varBatteryLifeQ As String = "" Dim varMemoryQ As String = "" Dim varRam As String = "" Dim varScreenSize As String = "" Dim varWebcam As String = "" myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True") myConnection.Open() varBatteryLifeQ = RadioButtonList1.SelectedValue.ToString varMemoryQ = RadioButtonList2.SelectedValue.ToString varRam = RadioButtonList3.SelectedValue.ToString varScreenSize = RadioButtonList4.SelectedValue.ToString varWebcam = RadioButtonList5.SelectedValue.ToString myCommand = New SqlCommand("Select * From LPU400 Where BatteryLife = '" + varBatteryLifeQ + "' AND Memory = '" + varMemoryQ + "' AND RAM ='" + varRam + "' AND ScreenSize ='" + varScreenSize + "' AND Webcam ='" + varWebcam + "'", myConnection) SqlDataSource2.SelectCommand = "Select * From LPU400 Where BatteryLife = '" + varBatteryLifeQ + "' AND Memory = '" + varMemoryQ + "' AND RAMQ ='" + varRam + "' AND ScreenSize ='" + varScreenSize + "' AND Webcam ='" + varWebcam + "'" SqlDataSource2.DataBind() dr = myCommand.ExecuteReader() While dr.Read() End While dr.Close() myConnection.Close() End Sub Thanks in advance, Daithi
-
Hi there.. :) im workin on a website at the moment in asp.net, using vb.net, in the visual studios 2008 IDE! i just wish to add an extra feature and hopefully someone out there might be able to help. I have a button that reads the values of 5 radio buttons in a radiobutton list, then queries the database, returning results based on the values selected. If no value is returned i wish to display a message saying "No Results this time, please search again" or something to that effect. Im not sure how to do this. here is the code i have behind the button.. Please advise. Protected Sub btnSuggest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSuggest.Click Dim myConnection As SqlConnection Dim myCommand As SqlCommand Dim dr As SqlDataReader Dim varBatteryLifeQ As String = "" Dim varMemoryQ As String = "" Dim varRam As String = "" Dim varScreenSize As String = "" Dim varWebcam As String = "" myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True") myConnection.Open() varBatteryLifeQ = RadioButtonList1.SelectedValue.ToString varMemoryQ = RadioButtonList2.SelectedValue.ToString varRam = RadioButtonList3.SelectedValue.ToString varScreenSize = RadioButtonList4.SelectedValue.ToString varWebcam = RadioButtonList5.SelectedValue.ToString myCommand = New SqlCommand("Select * From LPU400 Where BatteryLife = '" + varBatteryLifeQ + "' AND Memory = '" + varMemoryQ + "' AND RAM ='" + varRam + "' AND ScreenSize ='" + varScreenSize + "' AND Webcam ='" + varWebcam + "'", myConnection) SqlDataSource2.SelectCommand = "Select * From LPU400 Where BatteryLife = '" + varBatteryLifeQ + "' AND Memory = '" + varMemoryQ + "' AND RAMQ ='" + varRam + "' AND ScreenSize ='" + varScreenSize + "' AND Webcam ='" + varWebcam + "'" SqlDataSource2.DataBind() dr = myCommand.ExecuteReader() While dr.Read() End While dr.Close() myConnection.Close() End Sub Thanks in advance, Daithi
Before you proceed with
dr.Read()
checkif dr.HasRows
. If yes proceed to read, else put "No Results this time, please search again" in a label or some other place holder. HTH! -
Before you proceed with
dr.Read()
checkif dr.HasRows
. If yes proceed to read, else put "No Results this time, please search again" in a label or some other place holder. HTH!