i am using microsoft visual web express 2010 .can u guide me through the connection to ms -access 2007 .whatever the data is given by user ,it is to be stored in the access 2007
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As New OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim sda As New OleDbDataAdapter
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Try
con.Open()
If Me.Select1.Value = "User" Then
cmd = New OleDbCommand("select * from `USERS` where USERNAME='" & txtUsername.Text & "' and PASSWORD='" & txtPassword.Text & "'", con)
dr = cmd.ExecuteReader
dr.Read()
If txtUsername.Text = dr(8) And txtPassword.Text = dr(9) Then
Response.Redirect("USER.aspx")
End If
End If
If Me.Select1.Value = "Admin" Then
cmd = New OleDbCommand("select * from `ADMINUSERS` where USERNAME='" & txtUsername.Text & "' and PASSWORD='" & txtPassword.Text & "' ", con)
dr = cmd.ExecuteReader
dr.Read()
If txtUsername.Text = dr(8) And txtPassword.Text = dr(9) Then
Response.Redirect("Default.aspx")
End If
End If
Catch ex As Exception
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & Me.Server.MapPath("EMP.mdb")
End Sub
End Class
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Besides what hans_v's suggestion,I found that your SQL statement would cause the problem of SQL injection……So you should also change to OleDbParameter instead of using strings' combination together。See this similar sample of using OleDbParameter:
public DataSet GetDataSetFromAdapter(
DataSet dataSet, string connectionString, string queryString)
{
using (OleDbConnection connection =
new OleDbConnection(connectionString))
{
OleDbDataAdapter adapter =
new OleDbDataAdapter(queryString, connection);
// Set the parameters.
adapter.SelectCommand.Parameters.Add(
"@CategoryName", OleDbType.VarChar, 80).Value = "toasters";
adapter.SelectCommand.Parameters.Add(
"@SerialNum", OleDbType.Integer).Value = 239;
// Open the connection and fill the DataSet.try
{
connection.Open();
adapter.Fill(dataSet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the// code exits the using block.
}
return dataSet;
}
saradav
Member
31 Points
80 Posts
connection
Feb 19, 2012 10:49 AM|LINK
i am using microsoft visual web express 2010 .can u guide me through the connection to ms -access 2007 .whatever the data is given by user ,it is to be stored in the access 2007
dinakaran
Member
625 Points
216 Posts
Re: connection
Feb 19, 2012 11:01 AM|LINK
Hi
Please follow this link
http://www.connectionstrings.com/access-2007
i hope it helps you.
venkatmca008
Participant
1810 Points
341 Posts
Re: connection
Feb 19, 2012 11:20 AM|LINK
hi...my program...use this..
Imports System.Data.OleDb Partial Class _Default Inherits System.Web.UI.Page Dim con As New OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim sda As New OleDbDataAdapter Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click Try con.Open() If Me.Select1.Value = "User" Then cmd = New OleDbCommand("select * from `USERS` where USERNAME='" & txtUsername.Text & "' and PASSWORD='" & txtPassword.Text & "'", con) dr = cmd.ExecuteReader dr.Read() If txtUsername.Text = dr(8) And txtPassword.Text = dr(9) Then Response.Redirect("USER.aspx") End If End If If Me.Select1.Value = "Admin" Then cmd = New OleDbCommand("select * from `ADMINUSERS` where USERNAME='" & txtUsername.Text & "' and PASSWORD='" & txtPassword.Text & "' ", con) dr = cmd.ExecuteReader dr.Read() If txtUsername.Text = dr(8) And txtPassword.Text = dr(9) Then Response.Redirect("Default.aspx") End If End If Catch ex As Exception End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & Me.Server.MapPath("EMP.mdb") End Sub End ClassMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
ramiramilu
All-Star
95413 Points
14106 Posts
Re: connection
Feb 19, 2012 11:54 AM|LINK
Insert/Update/Select to MS Access in asp.net - http://msdn.microsoft.com/en-us/library/ms971485.aspx
Thanks,
JumpStart
saradav
Member
31 Points
80 Posts
Re: connection
Feb 19, 2012 02:42 PM|LINK
Thank u very much can u jst xpalin the program ,in a brief way ,.If u dont mind.pls .since i have to do my project.................................
hans_v
All-Star
35986 Points
6550 Posts
Re: connection
Feb 19, 2012 05:55 PM|LINK
Please don't use this code!!!!
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: connection
Feb 21, 2012 12:39 AM|LINK
Hello vekatmca008:)
Besides what hans_v's suggestion,I found that your SQL statement would cause the problem of SQL injection……So you should also change to OleDbParameter instead of using strings' combination together。See this similar sample of using OleDbParameter:
hans_v
All-Star
35986 Points
6550 Posts
Re: connection
Feb 21, 2012 06:26 AM|LINK
That's exactly what the article I posted is all about!!!!!!