刚学C#,一段修改简单代码
点btn1,就执行updatedatebase方法,可是没任何反映分析得出this.myds.HasChanges()结果是 false,this.myds.GetChanges()这个对象得到的也是null
为什么会这样?逻辑那里出了问题,请大虾指教指教
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace database
{
public partial class Form1 : Form
{
public SqlDataAdapter myda = new SqlDataAdapter();
public DataSet myds = new DataSet();
public SqlCommandBuilder sqlcmdbld;
public Form1()
{
InitializeComponent();
SqlConnection sqlconn = new SqlConnection("server=LENOVO-1389D547;database=master;uid=sa;pwd=8233");
SqlDataAdapter myda = new SqlDataAdapter("select * from student", sqlconn);
DataSet myds = new DataSet();
myda.Fill(myds, "stu");
dataGridView1.DataSource = myds.Tables["stu"];
}
public DataSet updatedatebase(DataSet changedata)
{
this.sqlcmdbld = new SqlCommandBuilder(myda);
myda.Update(changedata);
return changedata;
}
private void btn1_Click(object sender, EventArgs e)
{if (this.myds.HasChanges())
{
this.updatedatebase(this.myds.GetChanges());
MessageBox.Show("修改成功");
}
}
}
}