asp.net SqlDataAdapter Update
使用 SqlDataAdapter的Update实现更新添加数据
代码
StringBuilder objSB = new StringBuilder();
objSB.Append("select * From ");
objSB.Append(destTableName);
objSB.Append(" Where ");
objSB.Append(destFilter);
SqlDataAdapter objAdapter = new SqlDataAdapter(objSB.ToString(), objConn);
SqlCommandBuilder objBuilder = new SqlCommandBuilder(objAdapter);
DataSet objDS = new DataSet();
DataTable objDest = new DataTable();
objAdapter.Fill(objDest);
this.UpdateRecordForTable(objSource,objDest,newValues); //处理数据
objAdapter.Update(objDest);
//更新纪录
public void UpdateRecordForTable(DataTable objSource, DataTable objDest, Hashtable newValues)
{
foreach(DataRow objSourceDR in objSource.Rows)
{
DataRow objDestDR = objDest.Rows[i];
。。。。。
}
}
//添加新的纪录
public void CopyRecordsForTable(DataTable objSource, DataTable objDest, Hashtable newValues)
{
foreach (DataRow objSourceDR in objSource.Rows)
{
DataRow objDestDR = objDest.NewRow();
。。。。。。。
objDest.Rows.Add(objDestDR);
}
}
objSB.Append("select * From ");
objSB.Append(destTableName);
objSB.Append(" Where ");
objSB.Append(destFilter);
SqlDataAdapter objAdapter = new SqlDataAdapter(objSB.ToString(), objConn);
SqlCommandBuilder objBuilder = new SqlCommandBuilder(objAdapter);
DataSet objDS = new DataSet();
DataTable objDest = new DataTable();
objAdapter.Fill(objDest);
this.UpdateRecordForTable(objSource,objDest,newValues); //处理数据
objAdapter.Update(objDest);
//更新纪录
public void UpdateRecordForTable(DataTable objSource, DataTable objDest, Hashtable newValues)
{
foreach(DataRow objSourceDR in objSource.Rows)
{
DataRow objDestDR = objDest.Rows[i];
。。。。。
}
}
//添加新的纪录
public void CopyRecordsForTable(DataTable objSource, DataTable objDest, Hashtable newValues)
{
foreach (DataRow objSourceDR in objSource.Rows)
{
DataRow objDestDR = objDest.NewRow();
。。。。。。。
objDest.Rows.Add(objDestDR);
}
}
继续追寻。。。。。。