private void btnName_Click(object sender, EventArgs e)
{
if (textBox1.Text.ToString() == "")
{
MessageBox.Show("请输入要更改的数据");
}
else
if (textBox1.Text.Trim().ToString() != null)
{
try
{
connection.Open();
string updatasql = "update student set 姓名='" + textBox1.Text + "'where 学号='" + name + "'";
string selectsql = string.Format("select 姓名,性别,出生日期,出生地,民族,毕业学校 from student where 学号='{0}'", name);
command = new SqlCommand(updatasql, connection);
if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("更新成功");
textBox1.Text = "";
}
else
MessageBox.Show("更新失败");
connection.Close();
adapter = new SqlDataAdapter(selectsql, connection);
dataset = new DataSet();
adapter.Fill(dataset);
dataGridViewShow.DataSource = dataset.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}我自己的一个例子,希望你看的懂