[求助]修改密码,提示表中没有主键!
修改密码,提示表中没有主键if (textBox2.Text == textBox3.Text)
{
try
{
if (conn.State == ConnectionState.Closed) conn.Open();
string t = ds.Tables["denglu"].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim();
string fing = "select * from denglu where name='" + t + "'";
OleDbCommand dc = new OleDbCommand(fing, conn);
OleDbDataReader read = dc.ExecuteReader();
if (read.Read())
{
if (textBox1.Text== read["password"].ToString())
{
DataRow row = ds.Tables["denglu"].Rows.Find(dataGridView1.CurrentRow.Index);
row.BeginEdit();
row["password"] = textBox2.Text;
row.EndEdit();
string str = "select * from denglu";
OleDbDataAdapter da = new OleDbDataAdapter(str, conn);
OleDbCommandBuilder db = new OleDbCommandBuilder(da);
da.UpdateCommand = db.GetUpdateCommand();
da.Update(ds, "denglu");
ds.AcceptChanges();
}
else
MessageBox.Show("原始密码不证确!");
}
else
MessageBox.Show("请在左边选择要修改的用户!");
}
finally
{
conn.Close();
}
}
else
MessageBox.Show("两次输入密码不一致!");