I need help for connecting my 'Access' database to asp.net website. Coding is in C# .
I was working on making a registration page, but since i was unable to connect, I tried a test code for login and it ain't working :icon_cry:
I am using the following code for showing form :
<asp:Literal ID="Literal1" runat="server" /><br />
User Name: <asp:TextBox ID="uname" runat="server" /><br />
Password: <asp:TextBox ID="upassword" runat="server" TextMode="Password" /><br />
<asp:Button ID="Login" runat="server" Text="Log In" onclick="Login_Click" />
I am using following code in .cs file :
string connect = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:|Users|Apache|Documents|jerry.mdb; User Id=Admin; Password=";
string query = "Select Count(*) From registration Where uname = ? And upassword = ?";
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.Parameters.AddWithValue("", uname.Text);
cmd.Parameters.AddWithValue("", upassword.Text);
conn.Open();
Session["registration"] = uname.Text;
result = (int)cmd.ExecuteScalar();
}
}
if (result > 0)
{
Response.Redirect("LoggedIn.aspx");
}
else
{
Literal1.Text = "Invalid credentials";
}
I have also included 'using System.Data.OleDb;' in starting.. and on running this test page, I get the following errors :
Source Error:
Line 30: cmd.Parameters.AddWithValue("", uname.Text);
Line 31: cmd.Parameters.AddWithValue("", upassword.Text);
Line 32: conn.Open();
Line 33: Session["registration"] = uname.Text;
Line 34: result = (int)cmd.ExecuteScalar();
Source File: c:\Users\Apache\Documents\Visual Studio 2008\WebSites\onlineshoppingplace\test.aspx.cs Line: 32
I even included the database 'jerry.mdb' to my database connection, started it from Control Panel > ODBC too.. I would be thankful if someone can teach me about it from 0 level (I mean that maybe I am doing something wrong with database :icon_mad: :confused:)