Therese Puno

Therese Puno

  • NA
  • 13
  • 0

ERROR on Reading Password and Username

Jul 18 2008 4:28 AM

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");

}

}

}


Answers (1)