DataRow aa = ds.Tables[0].NewRow();
aa.xxxx = xxxx
ds.Tables[0].Rows.Add(aa);

解决方案 »

  1.   

    你要在别的事件中添加,那么dataset必须是public类型的.private 是私有变量,别的事件里无法访问.
      

  2.   


    DataRow dr =  dataSet.Tables[0].NewRow();
    dr[""] ="";
    dataSet.Tables[0].Rows.Add(dr);
      

  3.   


    为什么  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呀
      

  4.   


    现在得需要往dataset里放多个table,需要用table名称,如果写序号的话就不行了
      

  5.   


    为什么  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?
      

  6.   

    引用位置可以,不过我这个dataset里有好多个table呀,用0的话我就不知道具体是哪个table了呀
      

  7.   

    ds.Tables[0]和ds.Tables["名称"]都能用
      

  8.   

    private DataSet dataSet = new DataSet();
      DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);
        dataSet.Tables.Add(convoyTimeTable);你这个convoyTimeTable不是table名称,而是table的变量名称
      

  9.   

    private DataSet dataSet = new DataSet();
      DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);
    convoyTimeTable,tablename="convoyTimeTable ";
        dataSet.Tables.Add(convoyTimeTable);然后你再试试
      

  10.   

    那如果我想在往dataset添加table的时候指定名称怎么做呢
      dataSet.Tables.Add("convoyTimeTable", convoyTimeTable);这样会出错
      

  11.   

    应该不是这里报错了吧,datarow的地方不报错么?你table里根本没有列,哪来的row[0],row[1]啊你要先table.columns.add("列名");
      

  12.   

      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();
        }
      

  13.   

    你有7列,要add 7次,每次列名不能相同.所以最好做个循环,for(int i=0;i<7;i++)
    {
    table.columns.add(i,type)
    }
      

  14.   

      DataTable convoyTimeTable = GetConvoyTimeByActivityID(activityID);这个语句就把存储过程里的列取出来了呀
      

  15.   

    DataRow row = dataSet.Tables["convoyTimeTable"].NewRow();这句话必须写到columns.add之后否则你在表中没有列的情况下生成的row,里面也是没有列的
      

  16.   

    那么你存储过程里是6列,你最终的table是7列对吗?执行了一次columns.add你newrow的时候要写在这之后啊