hi i want to show the message box using database conditions,,,,,
here my coding is given below.........

Protected Sub roomno_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles roomno.SelectedIndexChanged

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("guest1").ConnectionString())
        Try
            conn.Open()
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim da As New SqlClient.SqlCommand("select room_no from guesthouse  WHERE room_no =  '" & roomno.SelectedItem.Text & "' and status <> 'C'", conn)
            dr = da.ExecuteReader
            While dr.Read()
                MsgBox("this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! ")
            End While
        Catch ex As Exception
            conn.Close()
        End Try

    End Sub

here the problem is not showing any message........
pls help me........
give me the correct coding........
pls help me urgent..........

Recommended Answers

All 4 Replies

Hi

MsgBox function would not work on ASP.Net pages instead try using this to show alerts

Replace the following

MsgBox("this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! ")

with this and try

ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('" + "this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! " + "');</script>");

Hi

MsgBox function would not work on ASP.Net pages instead try using this to show alerts

Replace the following

MsgBox("this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! ")

with this and try

ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('" + "this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! " + "');</script>");

hi u have actually given code is not working ...........and it is not showing any error messages.........
why it is not working pls answer me .................

Hi,

Hope you had removed the ; at the end of the line before executing the code.

The code block should work. Since I dont have the working env of the database i was not able to execute the code and check. I just took the message withing the MSGBOX and replaced the same in the new syntax.

ClientScript.RegisterStartupScript would register a javascript and would show an alert message during execution.

Please try again in case of any issues please give the solution and the database will check the same and would let you know the correct fix.

Thanks
Vimal

Hi,

Hope you had removed the ; at the end of the line before executing the code.

The code block should work. Since I dont have the working env of the database i was not able to execute the code and check. I just took the message withing the MSGBOX and replaced the same in the new syntax.

ClientScript.RegisterStartupScript would register a javascript and would show an alert message during execution.

Please try again in case of any issues please give the solution and the database will check the same and would let you know the correct fix.

Thanks
Vimal

hi instead of your code i used the following code
but it shows error like "startIndex must be less than length of string."
why it was getting here my coding is as follows....
please help me urgent.........

Protected Sub roomno_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles roomno.SelectedIndexChanged

		conn.Open()
		Dim da As New SqlCommand("select room_no from guesthouse  WHERE room_no =  '" & roomno.SelectedItem.Text & "' and status <> 'C'", conn)
		Dim dr As System.Data.SqlClient.SqlDataReader
		dr = da.ExecuteReader
		If dr.Read() Then
			Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language=JavaScript>alert('" & "this room is booked from " & dr(0).ToString().Substring(0).Remove(10) & " to " & dr(1).ToString().Substring(0).Remove(10) & ".so this room is available from  the date " & dr(1).ToString().Substring(0).Remove(10) & " onwards! " & "');</script>")
		End If
		conn.Close()
end sub

thnx
raghu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.