求助!

niu_shu_zhan niu_shu_zhan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public partial class Form1 : Form
{

SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Student;Integrated Security=True");
SqlCommand command;

SqlDataAdapter adapter;

DataSet ds = new DataSet();

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e) //查询
{
string sql = "select*from studentinfo";

command = new SqlCommand(sql,cn);

adapter = new SqlDataAdapter(command);




if (ds.Tables["stu"] != null)
{
ds.Tables["stu"].Clear();
}


adapter.Fill(ds, "stu");

dataGridView1.DataSource = ds.Tables["stu"];

}

private void button2_Click(object sender, EventArgs e) //修改
{

SqlCommandBuilder bulider = new SqlCommandBuilder(adapter);


adapter.Update(ds,"stu"); //此处编译不通过


}
}
...全文
评论 6
收藏 已收藏
分享
返回顶部
niu_shu_zhan
.NET Framework 17,748 成员 24,324 内容