dimanche 19 avril 2015

c# Asp.net multiple SQL

Problem: 1) I would like to add multiple SQL command, like this , how can i do?



command.CommandText = "select * from Department where Name ='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'";





OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sim\Desktop\Web.accdb";
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "select * from Registration where Name ='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'";

OleDbDataReader reader = command.ExecuteReader();
int count = 0;

while (reader.Read())
{
count = count + 1;
}
if (String.IsNullOrEmpty(TextBox1.Text))
{
MessageBox.Show("You have't input the Username.");
}
if (String.IsNullOrEmpty(TextBox2.Text))
{
MessageBox.Show("you havn't input the Password.");
}
if (count == 1)
{

Session["UserID"] = TextBox1.Text ;
Response.Write("Username and password is valid");
connection.Close();
connection.Dispose();
Response.Redirect("Purchase.aspx", true);

}
else
{
MessageBox.Show("Username or Password is not matched");
}

Aucun commentaire:

Enregistrer un commentaire