实现简单数据库增删改查等功能
private void button2_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter();
MyDataSet = new DataSet();
string sql = "select * from stu_info";
da.SelectCommand = new SqlCommand(sql, conn);
SqlCommandBuilder myCB = new SqlCommandBuilder(da);
da.Fill(MyDataSet, "mytable");
for (int i = 0; i < MyDataSet.Tables["mytable"].Rows.Count - 1; i )
{
if (MyDataSet.Tables["mytable"].Rows[i]["xh"].ToString().Trim() == textBox1.Text.Trim())
{
MyDataSet.Tables["mytable"].Rows[i]["xm"] = textBox3.Text;
MyDataSet.Tables["mytable"].Rows[i]["stu_mima"] = textBox4.Text;
MyDataSet.Tables["mytable"].Rows[i]["xb"] = comboBox1.Text;
MyDataSet.Tables["mytable"].Rows[i]["age"] = textBox5.Text;
MyDataSet.Tables["mytable"].Rows[i]["jg"] = textBox6.Text;
MyDataSet.Tables["mytable"].Rows[i]["phone"] = textBox7.Text;
MyDataSet.Tables["mytable"].Rows[i]["qq"] = textBox8.Text;
MyDataSet.Tables["mytable"].Rows[i]["jtdz"] = textBox9.Text;
}
}
if(MyDataSet.HasChanges())
{
da.Update(MyDataSet, "mytable");
MessageBox.Show("修改成功!", "提示");
}
评论