v f

v f

  • NA
  • 3
  • 0

what is wrong in this code

Mar 23 2006 4:02 PM

private void button1_Click(object sender, EventArgs e)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\db4.MDB";
string strSQL = "SELECT * FROM ta1";

OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, myConn);
DataSet dtSet = new DataSet();

string sqlQuery = "SELECT Name,Password FROM ta1 where Name = '" + textBox1.Text.ToString() + "' AND Password= '" + textBox2.Text.ToString() + "'";

myCmd.SelectCommand.CommandText = sqlQuery;

int numberOfRowsFeched = myCmd.Fill(dtSet, "ta1");

if (numberOfRowsFeched > 0)
{
try
{
myCmd.UpdateCommand.CommandText = "UPDATE Users SET " + "Password = '" +textBox3.Text + "'" + " WHERE Name = '" + textBox1.Text + "'";
myCmd.UpdateCommand.Connection = myConn;
myCmd.UpdateCommand.ExecuteNonQuery();
MessageBox.Show("Record updated Successfully");
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch (System.Data.OleDb.OleDbException exp)
{
myConn.Close();
MessageBox.Show(exp.Message);
}

}
else
{
MessageBox.Show("wrong Name Or Password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}

message : http://www.cpestudents.net/upload/up/54.gif


Answers (3)