110,502
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace 数据更新
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisconn = new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=northwind");
thisconn.Open();
SqlDataAdapter thisAdapter=new SqlDataAdapter("SELECT * FROM Tabletest",thisconn);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "Tabletest");
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
thisAdapter.InsertCommand = commandBuilder.GetInsertCommand();
thisAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
thisAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();
Console.WriteLine("name before change:{0}", thisDataSet.Tables["Tabletest"].Rows[1]["姓名"]);
thisDataSet.Tables["Tabletest"].Rows[1]["姓名"] = "孙六";
thisAdapter.Update(thisDataSet, "Tabletest");
Console.WriteLine("name after change:{0}", thisDataSet.Tables["Tabletest"].Rows[1]["姓名"]);
thisconn.Close();
}
}
}
thisAdapter.InsertCommand = commandBuilder.GetInsertCommand();
thisAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
thisAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();