现问:如有一个现己够造的DataSet,能否申请一个新的DataAdapter,同样利用DataAdapter.update(DataSet)更新数据库? == 可以SqlConnection cn = new SqlConnection("..."); //只要表结构,不要表数据 SqlDataAdapter da = new SqlDataAdapter("Select yourField1,yourField2 FROM yourTable where 1 = 2", cn); SqlCommandBuilder cmd = new SqlCommandBuilder(da); cn.Open(); da.Update(yourDataSet); cn.Close();
==
可以SqlConnection cn = new SqlConnection("...");
//只要表结构,不要表数据
SqlDataAdapter da = new SqlDataAdapter("Select yourField1,yourField2 FROM yourTable where 1 = 2", cn);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
cn.Open();
da.Update(yourDataSet);
cn.Close();
{
conn.Open();
//
}
catch
{
}
finally
{
if(conn.State != ConnectionState.Closed && conn != null)
{
conn.Close();
}
}
构造好的Adapter中东西都是全的(连接,T-SQL等)
适配器就是要做这项工作的