SqlCommandBuilder问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
private void Form1_Load(object sender, EventArgs e)
{
load();
}
//窗体加载显示数据
public void load()
{
string cnt = "data source=.; initial catalog =ly; user id =sa; pwd =123";
SqlConnection conn = new SqlConnection(cnt);
string sql = "select * from table1";
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
}
//点击按钮更新
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认修改吗?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.Update(ds, "table1");
//MessageBox.Show("修改成功啥的");
}
}
}
}