更新时间:2023-12-01 08:29:22
只需继续执行您的代码-您就在正确的轨道上:
//调用SQL帮助程序类以获取初始数据
$后将您的数据集保存在此处p $ p>
DataTable dt = sql.ExecuteDataTable( sp_MyProc);
dt.Columns.Add( NewColumn,typeof(System.Int32));
foreach(dt.Rows中的DataRow行)
{
//需要将值设置为NewColumn列
row [ NewColumn] = 0; //或将其设置为其他值
}
//可能在设置所有新值How do I add a new
DataColumn
to aDataTable
object that already contains data?PseudoCode
//call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable("sp_MyProc"); dt.Columns.Add("NewColumn", type(System.Int32)); foreach(DataRow row in dr.Rows) { //need to set value to NewColumn column }
Just keep going with your code - you're on the right track:
//call SQL helper class to get initial data DataTable dt = sql.ExecuteDataTable("sp_MyProc"); dt.Columns.Add("NewColumn", typeof(System.Int32)); foreach(DataRow row in dt.Rows) { //need to set value to NewColumn column row["NewColumn"] = 0; // or set it to some other value } // possibly save your Dataset here, after setting all the new values