i used visual studio 2003 ,i am newbie

i Created a simple database access and link it below ,i want to use dataset and oledbapdater compare the input from textbox with username and password colums in file .mdb .

http://mkptrans-nt.com/BaiTapTn.mdb

interface drag drop


Login page :

http://mkptrans-nt.com/pic1.JPG


Viewmark page :


http://mkptrans-nt.com/pic2.JPG


Code Login :

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Data.OleDb; // them vao o day de goi OleCommand

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace thiTn2007

{

///

/// Summary description for WebForm1.

///

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.TextBox TextBox1;

protected System.Web.UI.WebControls.TextBox TextBox2;

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.Label Label3;

protected System.Web.UI.WebControls.Label Label4;

protected System.Web.UI.WebControls.Button Button1;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;

protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

protected System.Data.OleDb.OleDbConnection oleDbConnection1;

protected thiTn2007.DataSet1 dataSet11;

protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();

this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();

this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();

this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();

this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();

this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();

this.dataSet11 = new thiTn2007.DataSet1();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();

this.Button1.Click += new System.EventHandler(this.Button1_Click);

//

// oleDbDataAdapter1

//

this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;

this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;

this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;

this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {

new System.Data.Common.DataTableMapping("Table", "SinhVien", new System.Data.Common.DataColumnMapping[] {

new System.Data.Common.DataColumnMapping("ID", "ID"),

new System.Data.Common.DataColumnMapping("SVID", "SVID"),

new System.Data.Common.DataColumnMapping("username", "username"),

new System.Data.Common.DataColumnMapping("password", "password"),

new System.Data.Common.DataColumnMapping("ngaysinh", "ngaysinh"),

new System.Data.Common.DataColumnMapping("mark", "mark"),

new System.Data.Common.DataColumnMapping("address", "address")})});

this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;

//

// oleDbDeleteCommand1

//

this.oleDbDeleteCommand1.CommandText = @"DELETE FROM SinhVien WHERE (ID = ?) AND (SVID = ? OR ? IS NULL AND SVID IS NULL) AND (address = ? OR ? IS NULL AND address IS NULL) AND (mark = ? OR ? IS NULL AND mark IS NULL) AND (ngaysinh = ? OR ? IS NULL AND ngaysinh IS NULL) AND ([password] = ? OR ? IS NULL AND [password] IS NULL) AND (username = ? OR ? IS NULL AND username IS NULL)";

this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_SVID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SVID", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_SVID1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SVID", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_mark", System.Data.OleDb.OleDbType.SmallInt, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "mark", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_mark1", System.Data.OleDb.OleDbType.SmallInt, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "mark", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ngaysinh", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ngaysinh", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ngaysinh1", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ngaysinh", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_password", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_password1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null));

this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null));

//

// oleDbConnection1

//

this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDBatabase Locking Mode=1;Jet OLEDBatabase Password=;Data Source=""E:\Inetpub\wwwroot\thiTn2007\BaiTapTn.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False";

//

// oleDbInsertCommand1

//

this.oleDbInsertCommand1.CommandText = "INSERT INTO SinhVien(SVID, username, [password], ngaysinh, mark, address) VALUES " +

"(?, ?, ?, ?, ?, ?)";

this.oleDbInsertCommand1.Connection = this.oleDbConnection1;

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("SVID", System.Data.OleDb.OleDbType.VarWChar, 50, "SVID"));

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("username", System.Data.OleDb.OleDbType.VarWChar, 50, "username"));

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("password", System.Data.OleDb.OleDbType.VarWChar, 50, "password"));

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ngaysinh", System.Data.OleDb.OleDbType.DBDate, 0, "ngaysinh"));

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("mark", System.Data.OleDb.OleDbType.SmallInt, 0, "mark"));

this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("address", System.Data.OleDb.OleDbType.VarWChar, 50, "address"));

//

// oleDbSelectCommand1

//

this.oleDbSelectCommand1.CommandText = "SELECT ID, SVID, username, [password], ngaysinh, mark, address FROM SinhVien WHER" +

"E (username = ?) AND ([password] = ?)";

this.oleDbSelectCommand1.Connection = this.oleDbConnection1;

this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("username", System.Data.OleDb.OleDbType.VarWChar, 50, "username"));

this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("password", System.Data.OleDb.OleDbType.VarWChar, 50, "password"));

//

// oleDbUpdateCommand1

//

this.oleDbUpdateCommand1.CommandText = @"UPDATE SinhVien SET SVID = ?, username = ?, [password] = ?, ngaysinh = ?, mark = ?, address = ? WHERE (ID = ?) AND (SVID = ? OR ? IS NULL AND SVID IS NULL) AND (address = ? OR ? IS NULL AND address IS NULL) AND (mark = ? OR ? IS NULL AND mark IS NULL) AND (ngaysinh = ? OR ? IS NULL AND ngaysinh IS NULL) AND ([password] = ? OR ? IS NULL AND [password] IS NULL) AND (username = ? OR ? IS NULL AND username IS NULL)";

this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("SVID", System.Data.OleDb.OleDbType.VarWChar, 50, "SVID"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("username", System.Data.OleDb.OleDbType.VarWChar, 50, "username"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("password", System.Data.OleDb.OleDbType.VarWChar, 50, "password"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ngaysinh", System.Data.OleDb.OleDbType.DBDate, 0, "ngaysinh"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("mark", System.Data.OleDb.OleDbType.SmallInt, 0, "mark"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("address", System.Data.OleDb.OleDbType.VarWChar, 50, "address"));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_SVID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SVID", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_SVID1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SVID", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_mark", System.Data.OleDb.OleDbType.SmallInt, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "mark", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_mark1", System.Data.OleDb.OleDbType.SmallInt, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "mark", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ngaysinh", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ngaysinh", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ngaysinh1", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ngaysinh", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_password", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_password1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null));

this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null));

//

// dataSet11

//

this.dataSet11.DataSetName = "DataSet1";

this.dataSet11.Locale = new System.Globalization.CultureInfo("en-US");

this.Load += new System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{

//Chuyen Trang nhung phai kiem tra loi

string tensinhvien = TextBox1.Text;

string matkhau = TextBox2.Text;

Session["ten"] = TextBox1.Text;

oleDbConnection2.Open();

OleDbCommand cmd = oleDbConnection2.CreateCommand();

oleDbDataAdapter1.SellectCommand.Parameters.Add("@ten",tensinhvien);

oleDbDataAdapter1.SellectCommand.Parameters.Add("@pass",matkhau);

oleDbDataAdapter1.SellectCommand.CommandText = " Select * From SinhVien Where username = @ten And password = @pass";

oleDbDataAdapter1.Fill(dataSet21);

if(dataSet21.Tables["SinhVien"|index].Rows.Count==0)

{

Label4.Text = "Dang Nhap Sai ten hoac pass dang nhap lai !" ;

}

else

{

Session["valid"] = dataSet21.Tables.["SinhVien"|index].Rows.Count==0

}

//check type on text box if users are typed direct to viewmarks page .

if(RequiredFieldValidator1.Visible.Equals(true) || RequiredFieldValidator2.Visible.Equals(true))

Response.Redirect("viewmarks.aspx");

}

private void oleDbDataAdapter1_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e)

{

}

}

}

Code ViewMarks :

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace thiTn2007

{

///

/// Summary description for WebForm2.

///

public class WebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//check session valid

if ( (Int32)Session["valid"] = 0 )

{

Response.Redirect("login.aspx");

}

Label1.Text = Session["ten"].ToString() ;//display userlogin now bi bao loi

}


#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

=============================================

what wrong with mine !? please. correct it ,i need code it for graduating .
in the additions, i need to creating a session to move sql query in login page import to datagrid in viewmarks page .

repost that using the code tags


[ code="csharp ]

your code here

[ / code ]

without the spaces of course.

Thank you.
The database has two fields in the Users table. A UserID field, which is the primary key and declared as a text. The other field is Password, which is a text as well.
And i want to compare value which have been input from username and password textboxs (like as :http://mkptrans-nt.com/pic1.JPG) with value from USERID field and Password Field .I want to use oledbadapter instead of Datareader .
My code(i think this wrong code ,please correct it ...) :

private void Button1_Click(object sender, System.EventArgs e)

{

//Chuyen Trang nhung phai kiem tra loi

string username = TextBox1.Text;

string password = TextBox2.Text;

Session["user"] = TextBox1.Text;

oleDbConnection2.Open();

OleDbCommand cmd = oleDbConnection2.CreateCommand();

oleDbDataAdapter1.SellectCommand.Parameters.Add("@user",username);

oleDbDataAdapter1.SellectCommand.Parameters.Add("@pass",password);

oleDbDataAdapter1.SellectCommand.CommandText = " Select * From SinhVien Where UserID = @user And Password = @pass";
oleDbDataAdapter1.Fill(dataSet21);
if(dataSet21.Tables["Users"|index].Rows.Count==0)
{
Label4.Text = "Dang Nhap Sai ten hoac pass dang nhap lai !" ;
}
else
{
Session["valid"] = dataSet21.Tables.["User"|index].Rows.Count==0
}
//check type on text box if users are typed direct to viewmarks page .

if(RequiredFieldValidator1.Visible.Equals(true) || RequiredFieldValidator2.Visible.Equals(true))
Response.Redirect("viewmarks.aspx");
}

This article has been dead for over six months. Start a new discussion instead.