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.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 herecn.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 ThenSession(
"LoginOk") = TrueResponse.Redirect(
"index.aspx") ElseLabel1.Text =
"Invalid username or password" End If ' Catch ex As Exception ' Label1.Text = ex.Message ' End Try End SubEnd
ClassPublic
Class login Inherits System.Web.UI.Page#
Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer.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 herecn.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 ThenSession(
"LoginOk") = TrueResponse.Redirect(
"index.aspx") ElseLabel1.Text =
"Invalid username or password" End If ' Catch ex As Exception ' Label1.Text = ex.Message ' End Try End SubEnd
Class
Chandu VisualsoftPosted Aug 22, 2007, 11:03 AM
Change Connection string enough
in asp.net using system.data.oledb should be changed to using system.data.sqlclient
and use key value pairs in web.config
put u r connection string in value and access that key name from config file to u r file with appsettings
done
BYPsoftPosted Aug 21, 2007, 4:16 AM
Dim cn As New SqlConnection
Dim cm As New SqlCommand
Dim dr As SqlDataReader
BYPsoftPosted Aug 21, 2007, 4:07 AM
using System.Data.SqlClient;
than change your Button1_Click procedure to use instead of
Dim cn As New OleDb.OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
following:
Dim cn As New SQLbConnection
Dim cm As New SQLCommand
Dim dr As SQLDataReader
Change your connection string in web.config to SQLServer's one:
Data Source=myServer;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
or
Data Source=myServer;Initial Catalog=myDataBase;Integrated Security=SSPI;
depending if you are using SQL authentication or trusted connection.
After this changes if your code works with Access it will also work with SQLServer.
Hope this helps.