SqlCommandBuilder (供自己查阅)
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WorkFlow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds;
SqlDataAdapter myAdapter;
SqlCommandBuilder myCommandBuilder;
private void Form1_Load(object sender, EventArgs e)
{
string str = "data source=(local);persist security info=false;initial catalog=WorkFlow;integrated security=true";
SqlConnection con = new SqlConnection(str);
ds = new DataSet();
con.Open();
myAdapter = new SqlDataAdapter("select * from T_user",con);
myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.InsertCommand = myCommandBuilder .GetInsertCommand();
myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
myAdapter.DeleteCommand = myCommandBuilder .GetDeleteCommand();
myAdapter.Fill(ds);
ds.Tables[0].Rows[0][1] = "123";
dataGridView1.DataSource = ds.Tables[0];
myAdapter.Update(ds);
con.Close();
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WorkFlow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds;
SqlDataAdapter myAdapter;
SqlCommandBuilder myCommandBuilder;
private void Form1_Load(object sender, EventArgs e)
{
string str = "data source=(local);persist security info=false;initial catalog=WorkFlow;integrated security=true";
SqlConnection con = new SqlConnection(str);
ds = new DataSet();
con.Open();
myAdapter = new SqlDataAdapter("select * from T_user",con);
myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.InsertCommand = myCommandBuilder .GetInsertCommand();
myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
myAdapter.DeleteCommand = myCommandBuilder .GetDeleteCommand();
myAdapter.Fill(ds);
ds.Tables[0].Rows[0][1] = "123";
dataGridView1.DataSource = ds.Tables[0];
myAdapter.Update(ds);
con.Close();
}
}

浙公网安备 33010602011771号