C# SqlDataAdapter.Update的用法

2025-01-04 04:58:59
推荐回答(1个)
回答1:

可以啊,你自己将它写成一个类就可以了。
例如:
public DataSet GetData(string selecttext, SqlParameter[] parmes, string keyset, string tablename, Boolean g)
{
try
{
connection = new SqlConnection(connectionstring);
dataadapter = new SqlDataAdapter();
dataadapter.SelectCommand = this.CommandFile(selecttext, parmes, g);
SqlCommandBuilder SCB = new SqlCommandBuilder(dataadapter);
ds = new DataSet();
dataadapter。fill(ds,tablename);
}
catch { }
return ds;
}
返回ds,填充表格。
public Boolean updatate(string dstablename, string selecttext, Boolean g, DataTable dt)
{
Boolean f = false;
int i = 0;
try
{
if (selecttext != null)
{
connection = new SqlConnection(connectionstring);
dataadapter = new SqlDataAdapter();
dataadapter.SelectCommand = this.CommandFile(selecttext, null, g);
SqlCommandBuilder SCB = new SqlCommandBuilder(dataadapter);
}
if (dstablename != null)
{
i = dataadapter.Update(ds.Tables[dstablename]);
}
if (dt != null)
{
i = dataadapter.Update(dt);
}
if (i > 0)
{
f = true;
}
}
catch (Exception ex) { }
return f;
}
根据实际情况来写入参数,调用不同的更新。