Protected Sub btnlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim command1 As New SqlCommand
Dim sqlread1 As SqlDataReader
Try
Connect1.Openconnection()
command1.Connection = Connect1.consql1
command1.CommandText = "select User_name,password from Login where User_name='" + txtUsername.Text + "' and password='" + txtPass.Text + "'"
sqlread1 = command1.ExecuteReader
If Not sqlread1.HasRows Then
lblMessage.Visible = True
lblMessage.Text = "Invalid UserName or Password"
Exit Sub
Else
lblMessage.Text = ""
If ddldesignation.SelectedItem.Text = "Additional Secretary" Then
Response.Redirect("~/Internal Audit.aspx")
ElseIf ddldesignation.SelectedItem.Text = "Director" Then
Response.Redirect("~/Leave Details.aspx")
ElseIf ddldesignation.SelectedItem.Text = "Acting Director" Then
Response.Redirect("~/Personal Information view.aspx")
ElseIf ddldesignation.SelectedItem.Text = "User" Then
Response.Redirect("~/PublicCommunication view.aspx")
End If
Do While sqlread1.Read()
'SAVE THE USERNAME TO COOKIES
Dim usercookie As HttpCookie = New HttpCookie("User_name")
usercookie.Values.Add("User_name", sqlread1("User_name"))
usercookie.Expires = #12/31/2013#
'place it on the footer
lblMessage.Visible = True
lblMessage.Text = sqlread1("User_name")
Session("User_name") = txtUsername.Text
'redirect to topic page
Response.Redirect("Menu.aspx?User_name=" & sqlread1("User_name"))
Loop
End If
Catch ex As Exception
Finally
Connect1.closeconnection()
End Try
Connect1.closeconnection()
End Sub
In this code out put is always Response.Redirect("Menu.aspx?User_name=" & sqlread1("User_name"))................ But i want to ddldesignation.SelectedItem.Text = "Additional Secretary" Then
Response.Redirect("~/Internal Audit.aspx") according to designation..please help to execute this code
Suthish NairPosted Mar 27, 2013, 6:39 AM
Vaibhav KanasePosted Mar 27, 2013, 6:25 AM
This is your database connection string and this is global connection string create one time and access on code page (.vb) where u have error.
Or
Remove
Dim cn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constr").ToString
AND copy following code and paste with your Connection string
Dim cn As New SqlConnection("YOUR DATABASE CONNECTION STRING LIKE Data Source=PROMEETRA-006\SQLEXPRESS;Initial Catalog=your database name;Integrated Security=True")
Thanks
jayani chathurikaPosted Mar 27, 2013, 4:58 AM
Dim cn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constr").ToString())
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim da As SqlDataAdapter
Dim rtnstatus As Boolean
Dim query As String
query = "select User_name,password from Login where User_name='" + txtUsername.Text + "' and password='" + txtPass.Text + "'"
cmd = New SqlCommand(query, cn)
dr = cmd.ExecuteReader
If dr.Read Then
'Your valid code
Else
'lblmsg.Text = "Pls check your login detail."
End If
cn.Close()
Vaibhav KanasePosted Mar 27, 2013, 3:31 AM
Dim cn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constr").ToString())
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim da As SqlDataAdapter
Dim rtnstatus As Boolean
Dim query As String
query = "select User_name,password from Login where User_name='" + txtUsername.Text + "' and password='" + txtPass.Text + "'"
cmd = New SqlCommand(query, cn)
dr = cmd.ExecuteReader
If dr.Read Then
'Your valid code
Else
'lblmsg.Text = "Pls check your login detail."
End If
cn.Close()