SqlDataAdapter.Update问题:我该怎么写这个函数?
写一个类Test
class Test
{
private SqlConnection Conn;
private DataSet ds;
private SqlDataAdapter da;
private SqlCommandBuilder cb;
public Test()
{
//建立数据库链接,把table表中的所有数据读取到DataSet中.
ds = new DataSet( "DS" );
Conn = new SqlConnection( "Data Source=localhost;Initial Catalog=Test;User Id=sa;Password=;" );
da = new SqlDataAdapter( "select * from table", Conn );
da.Fill( ds );
}
public void Update()
{
//将DataSet中的修改用da.update方法保存到数据库中.
//谁能给我写这个函数???
///谢谢
}
//后面还有一些函数,都是用于修改DataSet中数据的,我在这里就不写了.
}
参考答案:using System;
using System.Data.SqlClient;
class Test
{
private SqlConnection Conn;
private DataSet ds;
private SqlDataAdapter da;
private SqlCommandBuilder cb;
public Test()
{
//建立数据库链接,把table表中的所有数据读取到DataSet中.
ds = new DataSet( "DS" );
Conn = new SqlConnection( "Data Source=localhost;Initial Catalog=Test;User Id=sa;Password=;" );
da = new SqlDataAdapter( "select * from table", Conn );
da.Fill( ds );
//你对dataset的修改
da.Update(ds);
Conn.Close();
}