I use Access DB in this cood what i want it to use SQL server (DB) what i can do to change this cood ????? and also what i can write in Web.config.??
Public
Class login
Inherits System.Web.UI.Page
#
Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#
End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New OleDb.OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim username As String = TextBox1.Text
Dim password As String = TextBox2.Text
' Try
' open connection here
cn.ConnectionString = ConfigurationSettings.AppSettings(
"ConnectionString")
cn.Open()
cm.Connection = cn
cm.CommandText =
"Select * From Users Where Username='" & username _
&
"' AND Password='" & password & "'"
dr = cm.ExecuteReader()
If dr.HasRows Then
Session(
"LoginOk") = True
Response.Redirect(
"index.aspx")
Else
Label1.Text =
"Invalid username or password"
End If
' Catch ex As Exception
' Label1.Text = ex.Message
' End Try
End Sub
End
Class
Public
Class login
Inherits System.Web.UI.Page
#
Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#
End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New OleDb.OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Dim username As String = TextBox1.Text
Dim password As String = TextBox2.Text
' Try
' open connection here
cn.ConnectionString = ConfigurationSettings.AppSettings(
"ConnectionString")
cn.Open()
cm.Connection = cn
cm.CommandText =
"Select * From Users Where Username='" & username _
&
"' AND Password='" & password & "'"
dr = cm.ExecuteReader()
If dr.HasRows Then
Session(
"LoginOk") = True
Response.Redirect(
"index.aspx")
Else
Label1.Text =
"Invalid username or password"
End If
' Catch ex As Exception
' Label1.Text = ex.Message
' End Try
End Sub
End
Class