Hi,
I was new to c# and asp.net .I want to create a simple login page using ASP.net with c# code behind.I had 2 textboxs(username and id) and 1 button control.I stored all the username and id in MS ACCESS database.Database name "user.mdb" and table name
"table1" (only 2 fields username and password).Once users enter their username & id,and by clicking button control,it must check into the database.If is it in database means ,this login page call other .aspx page.if is it not in database means "error should arise not in the database".I dont how to proceed .........and i need a full code regarding on this.Please help me...........

Why not use Session Variables? Once the user is verified create a Session variable (e.g. Session("Verified") = "Yes"). In the Page Load check if the value is Yes. Much easier and quicker than a database access plus MS Access sucks as a multi-user database.

Please put some effort to write codings, I don't know how to clear your doubts. Are you asking for full coding from connection establishment upto validation.

First you need to get all the usernames and ids from the table, and then compare each with the username and id entered in the textboxes.

I will provide the code for sql database and try it for your MS ACCESS database.

Using System.Data.SqlClient;

Next in Button Click Event:
------------------------------

SqlConnection con=new SqlConnection();
con.ConnectionString="server=localhost;database=master;user id=sa";
(Specify as per ur databse)
con.Open();
SqlDataAdaptor da=new SqlDataAdapor("select * from tablename",con);
DataSet ds=new DataSet();
da.fill(ds,"tablename");

**Comapring the validations**

for(int i=0;i<=ds.Tables["Tablename"].Rows.count;i++)
{
       if(textBox1.Text==ds.Tables ["Tablename"].Rows[i][0])

{
     if(textBox2.Text==ds.Tables   ["Tablename"].Rows[i][1])
Server.Transfer("nextpage.aspx");
else
{
  Response.Write("Invalid");
}
else
Response.Write("Invalid");


}
}

====Try the above Code and let me know the results==========

First you need to get all the usernames and ids from the table, and then compare each with the username and id entered in the textboxes.

I will provide the code for sql database and try it for your MS ACCESS database.

Using System.Data.SqlClient;

Next in Button Click Event:
------------------------------

SqlConnection con=new SqlConnection();
con.ConnectionString="server=localhost;database=master;user id=sa";
(Specify as per ur databse)
con.Open();
SqlDataAdaptor da=new SqlDataAdapor("select * from tablename",con);
DataSet ds=new DataSet();
da.fill(ds,"tablename");

**Comapring the validations**

for(int i=0;i<=ds.Tables["Tablename"].Rows.count;i++)
{
if(textBox1.Text==ds.Tables ["Tablename"].Rows[0])

{
if(textBox2.Text==ds.Tables ["Tablename"].Rows[1])
Server.Transfer("nextpage.aspx");
else
{
Response.Write("Invalid");
}
else
Response.Write("Invalid");


}
}


====Try the above Code and let me know the results==========

Hi
I try for Ms access database .But i got 2 errors and 2 warning message.The list of errors are:
Error 1 The name 'da' does not exist in the current context.
Error 2 'System.Data.DataRowCollection' does not contain a definition for 'count' .
Warning 3 Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'.
Warning 4 Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'

Here's my code:

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class sample1_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\login.mdb;Persist Security Info=False");
        conn.Open();
        OleDbCommand com = new OleDbCommand("select * from logintable",conn);
        DataSet ds=new DataSet();
        da.fill(ds,"logintable");

        for (int i = 0; i <= ds.Tables["Tablename"].Rows.count; i++)
        {
            if (TextBox1.Text == ds.Tables["Tablename"].Rows[i][0])
            {
                if (TextBox2.Text == ds.Tables["Tablename"].Rows[i][1])
                {
                    Server.Transfer("reservation.aspx");
                }
                else
                {
                    Response.Write("Invalid");
                }
            }
            else
            {

                Response.Write("Invalid");

            }
        }
    }
}

Thanks girigdk.......

hi,
in this code errors are, da.fill(ds,"logintable"); here where did u create object da for dataadapter.so create object then ur problems will be solved. suggetion: if (TextBox2.Text == ds.Tables["Tablename"].Rows[1])
{
// create session for user which can be useful in throughout the appication
Server.Transfer("reservation.aspx");
}

hope it will be helpful

This question has already been answered. Start a new discussion instead.