我的好使了,好用了,给大家参考学习一下吧,!
我的语句好用的,!
private void button1_Click(object sender, System.EventArgs e)
{
try
{
this.dataSet1.Clear();
string update="Update admin set udname='"+this.comboBox2.Text+"', udpassword='"+this.comboBox3.Text+"' where id='"+this.comboBox1.Text+"'";
SqlCommand comm=new SqlCommand();
comm.CommandText=update;
comm.Connection=this.sqlConnection1;
this.sqlConnection1.Open();
comm.ExecuteNonQuery();
this.sqlConnection1.Close();
//更新数据库
this.sqlDataAdapter1.Fill(this.dataSet1,"admin");
this.dataGrid1.DataSource=this.dataSet1;
}
catch(Exception Err)
{
MessageBox.Show("修改数据库记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
//如果打开了连接,则关闭它
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
}