Hi...frnds
My Code for checking the availability of USER and the PASSWORD in the Database isnt working...
will you please help me..
private
void CmdLogIn_Click(object sender, EventArgs e){
try{
SqlConnection SqlCon = new SqlConnection(@"SERVER = SOLOMON; User ID=sa;password=sa;Initial Catalog=EBank;Data Source=solomon"); SqlCon.Open(); string UsrName = Convert.ToString(CboUserName.Text); string PasWOrd = Convert.ToString(TxtPassword.Text); SqlCommand LogInCmd = new SqlCommand("spUserLogIn", SqlCon); LogInCmd.CommandType = CommandType.StoredProcedure; LogInCmd.Parameters.Add("UserName", SqlDbType.Char, 10).Value = UsrName; LogInCmd.Parameters.Add("Password", SqlDbType.Char, 10).Value = PasWOrd; SqlDataAdapter Adap = new SqlDataAdapter(LogInCmd); DataSet dSet = new DataSet(); Adap.Fill(dSet, "MyTable");while(Adap.read)
{
Un = Adap["UserName"]; Up = Adap["Password"];}
Adap.Close(); if(UsrName == Un && PasWOrd == Up){
Form newForm = new ImpBankStatementFrm(); newForm.MdiParent = this; newForm.Show();}
else{
MessageBox.Show("Your name and your password not match in database...", "Message...", MessageBoxButtons.OK, MessageBoxIcon.Question); TextBox1.Focus();}
}
catch (FormatException){
MessageBox.Show("Please Provide User Name", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);}
catch (OverflowException){
MessageBox.Show("Please Provide Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);}
catch (Exception ex){
MessageBox.Show(ex.Message, "System Error");}
}
}
ArshadPosted Jul 18, 2008, 6:06 AM
Try to to some thing Like that
string myConnectString = "Data Source=NBAP25169578480;Initial Catalog=employee;Integrated Security=True";
SqlConnection con = new SqlConnection(myConnectString);
SqlCommand cmd = new SqlCommand("select * from emp",con);
//After That Use the Adapter and fill the Dataset with that //table Then
SqlDataAdapter da=new SqlDataAdapter();
DataSet ds =new DataSet();
da.Fill(ds);
if(ds.Tables(0).Rows(0).Item("UserID")=txtUserId.Text)and
(ds.Tables(0).Rows(0).Item("password")=txtPassword.Text)
{Response.Redirect("Home.aspx");
}
This is not very Standard, but for ur reference i have give some thing Like that,Just test it i dint test it May be it can give some Error. but Logic is Correct.But Instead of DataSet try to use DataReader coz its Read only and forword Only.Thats All, thanks