dataset datatable datarow DataRow aa = ds.Tables[0].NewRow();aa.xxxx = xxxxds.Tables[0].Rows.Add(aa); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要在别的事件中添加,那么dataset必须是public类型的.private 是私有变量,别的事件里无法访问. DataRow dr = dataSet.Tables[0].NewRow();dr[""] ="";dataSet.Tables[0].Rows.Add(dr); 为什么 DataRow row = dataSet.Tables["convoyTimeTable"].NewRow(); dataSet.Tables[0].Columns.Add("",typeof(int)); int activityID = 25; row[0] = activityID; row[1] = txt_convory_StartData.Text; row[2] = txt_convory_StartTime.Text; row[3] = txt_convory_StartMinute.Text; row[4] = txt_convory_EndData.Text; row[5] = txt_convory_EndTime.Text; row[6] = txt_convory_EndMinute.Text; dataSet.Tables["convoyTimeTable"].Rows.Add(row);会报未将对象引用设置到对象的实例。明明往dataset放table的名称就是convoyTimeTable呀 现在得需要往dataset里放多个table,需要用table名称,如果写序号的话就不行了 为什么 DataRow row = dataSet.Tables["convoyTimeTable"].NewRow(); dataSet.Tables[0].Columns.Add("",typeof(int)); int activityID = 25; row[0] = activityID; row[1] = txt_convory_StartData.Text; row[2] = txt_convory_StartTime.Text; row[3] = txt_convory_StartMinute.Text; row[4] = txt_convory_EndData.Text; row[5] = txt_convory_EndTime.Text; row[6] = txt_convory_EndMinute.Text; dataSet.Tables["convoyTimeTable"].Rows.Add(row);会报未将对象引用设置到对象的实例。明明往dataset放table的名称就是convoyTimeTable呀你先写成[0],看能不能引用到,如果还是找不到,那就是类型的问题你确定引用的位置能访问dataset? 引用位置可以,不过我这个dataset里有好多个table呀,用0的话我就不知道具体是哪个table了呀 ds.Tables[0]和ds.Tables["名称"]都能用 private DataSet dataSet = new DataSet(); DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID); dataSet.Tables.Add(convoyTimeTable);你这个convoyTimeTable不是table名称,而是table的变量名称 private DataSet dataSet = new DataSet(); DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);convoyTimeTable,tablename="convoyTimeTable "; dataSet.Tables.Add(convoyTimeTable);然后你再试试 那如果我想在往dataset添加table的时候指定名称怎么做呢 dataSet.Tables.Add("convoyTimeTable", convoyTimeTable);这样会出错 应该不是这里报错了吧,datarow的地方不报错么?你table里根本没有列,哪来的row[0],row[1]啊你要先table.columns.add("列名"); DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID); convoyTimeTable.TableName = "convoyTimeTable"; gv_convory.DataSource = convoyTimeTable;//填充护航时间表 gv_convory.DataBind(); /// <summary> /// 执行添加 /// </summary> protected void convory_trime_add(object sender,EventArgs e) { //Response.Write(dataSet.Tables[0].); DataRow row = dataSet.Tables["convoyTimeTable"].NewRow(); dataSet.Tables[0].Columns.Add("",typeof(int)); int activityID = 25; row[0] = activityID; row[1] = txt_convory_StartData.Text; row[2] = txt_convory_StartTime.Text; row[3] = txt_convory_StartMinute.Text; row[4] = txt_convory_EndData.Text; row[5] = txt_convory_EndTime.Text; row[6] = txt_convory_EndMinute.Text; dataSet.Tables["convoyTimeTable"].Rows.Add(row); //进行数据绑定 //ReverseRepair(); gv_convory.DataSource = dataSet.Tables["convoyTimeTable"]; gv_convory.DataBind(); } 你有7列,要add 7次,每次列名不能相同.所以最好做个循环,for(int i=0;i<7;i++){table.columns.add(i,type)} DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);这个语句就把存储过程里的列取出来了呀 DataRow row = dataSet.Tables["convoyTimeTable"].NewRow();这句话必须写到columns.add之后否则你在表中没有列的情况下生成的row,里面也是没有列的 那么你存储过程里是6列,你最终的table是7列对吗?执行了一次columns.add你newrow的时候要写在这之后啊 c# 正态分布的累积分布函数表达式 c# 打开JPG文件,JPG文件名含有“-”,报错 Asp.net(C#)访问Oracle数据库,不定时出现无效操作。连接被关闭。 新手请教XML 画图!!! C#怎么不停的打开关闭数据里网址但是不在页面上面显示呢? datagridview选中行copy某cell的问题 高手请进 Web.config配置错误 关于dateTimePicker1提交数据库的问题 好像属性不能被继承和重载? substring . 紧急 winfrom 改变panel大小
DataRow dr = dataSet.Tables[0].NewRow();
dr[""] ="";
dataSet.Tables[0].Rows.Add(dr);
为什么 DataRow row = dataSet.Tables["convoyTimeTable"].NewRow();
dataSet.Tables[0].Columns.Add("",typeof(int));
int activityID = 25;
row[0] = activityID;
row[1] = txt_convory_StartData.Text;
row[2] = txt_convory_StartTime.Text;
row[3] = txt_convory_StartMinute.Text;
row[4] = txt_convory_EndData.Text;
row[5] = txt_convory_EndTime.Text;
row[6] = txt_convory_EndMinute.Text;
dataSet.Tables["convoyTimeTable"].Rows.Add(row);
会报未将对象引用设置到对象的实例。明明往dataset放table的名称就是convoyTimeTable呀
现在得需要往dataset里放多个table,需要用table名称,如果写序号的话就不行了
为什么 DataRow row = dataSet.Tables["convoyTimeTable"].NewRow();
dataSet.Tables[0].Columns.Add("",typeof(int));
int activityID = 25;
row[0] = activityID;
row[1] = txt_convory_StartData.Text;
row[2] = txt_convory_StartTime.Text;
row[3] = txt_convory_StartMinute.Text;
row[4] = txt_convory_EndData.Text;
row[5] = txt_convory_EndTime.Text;
row[6] = txt_convory_EndMinute.Text;
dataSet.Tables["convoyTimeTable"].Rows.Add(row);
会报未将对象引用设置到对象的实例。明明往dataset放table的名称就是convoyTimeTable呀你先写成[0],看能不能引用到,如果还是找不到,那就是类型的问题你确定引用的位置能访问dataset?
DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);
dataSet.Tables.Add(convoyTimeTable);你这个convoyTimeTable不是table名称,而是table的变量名称
DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);
convoyTimeTable,tablename="convoyTimeTable ";
dataSet.Tables.Add(convoyTimeTable);然后你再试试
dataSet.Tables.Add("convoyTimeTable", convoyTimeTable);这样会出错
convoyTimeTable.TableName = "convoyTimeTable";
gv_convory.DataSource = convoyTimeTable;//填充护航时间表
gv_convory.DataBind(); /// <summary>
/// 执行添加
/// </summary>
protected void convory_trime_add(object sender,EventArgs e)
{
//Response.Write(dataSet.Tables[0].);
DataRow row = dataSet.Tables["convoyTimeTable"].NewRow();
dataSet.Tables[0].Columns.Add("",typeof(int));
int activityID = 25;
row[0] = activityID;
row[1] = txt_convory_StartData.Text;
row[2] = txt_convory_StartTime.Text;
row[3] = txt_convory_StartMinute.Text;
row[4] = txt_convory_EndData.Text;
row[5] = txt_convory_EndTime.Text;
row[6] = txt_convory_EndMinute.Text;
dataSet.Tables["convoyTimeTable"].Rows.Add(row);
//进行数据绑定
//ReverseRepair();
gv_convory.DataSource = dataSet.Tables["convoyTimeTable"];
gv_convory.DataBind();
}
{
table.columns.add(i,type)
}