主题:帮我看看这个操作数据的修改字段问题
帮我看看这个操作数据的修改字段问题
不能修改数据库的数据?请指点下哪错了?
//修改银行用户名和密码方法
//这里有错,请指点
private void btnModify_Click(object sender, System.EventArgs e)
{
string cardId = this.cboCardId.Text;
string userName = this.txtUserName.Text.Trim();
string pwd = this.txtPassword.Text.Trim();
try
{
this.sqlAdapter = new SqlDataAdapter("select * from BankInfo",this.sqlConn);
dataSet = new DataSet();
this.sqlAdapter.Fill(dataSet,"BankInfo");
this.sqlAdapter.UpdateCommand = new SqlCommand("update BankInfo set UserName = '"+ userName +"',password = '"+ pwd +"' where CardId = '"+ cardId +"'",this.sqlConn);
this.sqlAdapter.Update(this.dataSet,"BankInfo");
MessageBox.Show("修改成功");
this.ClearFields();
this.dataGrid1.Update();
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.sqlConn.Close();
}
}
不能修改数据库的数据?请指点下哪错了?
//修改银行用户名和密码方法
//这里有错,请指点
private void btnModify_Click(object sender, System.EventArgs e)
{
string cardId = this.cboCardId.Text;
string userName = this.txtUserName.Text.Trim();
string pwd = this.txtPassword.Text.Trim();
try
{
this.sqlAdapter = new SqlDataAdapter("select * from BankInfo",this.sqlConn);
dataSet = new DataSet();
this.sqlAdapter.Fill(dataSet,"BankInfo");
this.sqlAdapter.UpdateCommand = new SqlCommand("update BankInfo set UserName = '"+ userName +"',password = '"+ pwd +"' where CardId = '"+ cardId +"'",this.sqlConn);
this.sqlAdapter.Update(this.dataSet,"BankInfo");
MessageBox.Show("修改成功");
this.ClearFields();
this.dataGrid1.Update();
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.sqlConn.Close();
}
}