你不应该用
objDataAdapter.Fill(ds,"Tmp_Pic");
来生成临时表。
应该用:
DataTable dt = new DataTable();
DataTable.TableName="Tmp_Pic";
ds.Tables["Tmp_Pic"].Columns.Add("id1");
//..更多字段
ds.Tables.Add(dt);
//....

解决方案 »

  1.   

    为什么你不在SqlDataAdapter(strSQL,objConnection)的StrSQL中实现然后再New ,Detset呢
      

  2.   

    照做,但是提示
    异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。源错误: 
    行 88:  {
    行 89: 
    行 90:  ds.Tables["Tmp_Pic"].Rows[j]["id1"]=ds.Tables["Pic_View"].Rows[i]["id"];
    行 91:  ds.Tables["Tmp_Pic"].Rows[j]["cate1"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    行 92:  }
     是否需要添加ds.Tables["Tmp_Pic"].NewRow();??
      

  3.   

    是啊,当你需要插入新行到这个临时表时,你要用 DataTable.NewRow()来生成一个空行。
      

  4.   

    if(i%6==0)
    {
    ds.Tables["Tmp_Pic"].NewRow();
    ds.Tables["Tmp_Pic"].Rows[j]["id1"]=ds.Tables["Pic_View"].Rows[i]["id"];
    ds.Tables["Tmp_Pic"].Rows[j]["cate1"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }还是报异常详细信息: System.IndexOutOfRangeException: 在位置 0 处没有任何行。
      

  5.   

    myRow = myDataTable.NewRow();
          myRow["id"] = i;
          myRow["item"] = "item " + i.ToString();
          myDataTable.Rows.Add(myRow);
      

  6.   

    for(int i=0;i<ds.Tables["Pic_View"].Rows.Count;i++){
    if(i%6==0){
    if(i!=0){
    j=j+1;
    }
    }

    if(i%6==0)
    {
    DataRow myRow=dt.NewRow();
    myRow["id1"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate1"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }
    if(i%6==1)
    {
    myRow["id2"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate2"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }
    if(i%6==2)
    {
    myRow["id3"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate3"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }
    if(i%6==3)
    {
    myRow["id4"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate4"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }
    if(i%6==4)
    {
    myRow["id5"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate5"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    }
    if(i%6==5)
    { myRow["id6"]=ds.Tables["Pic_View"].Rows[i]["id"];
    myRow["cate6"]=ds.Tables["Pic_View"].Rows[i]["BmpFile"];
    dt.Rows.Add(myRow);
    } }楼上的,不会写了,帮帮忙~
      

  7.   

    你的目的是当原来表中每六行合起来而已嘛:DataTable dt = new DataTable();
    DataTable.TableName="Tmp_Pic";
    ds.Tables["Tmp_Pic"].Columns.Add("id1");
    ds.Tables["Tmp_Pic"].Columns.Add("id2");
    ds.Tables["Tmp_Pic"].Columns.Add("id3");
    ds.Tables["Tmp_Pic"].Columns.Add("id4");
    ds.Tables["Tmp_Pic"].Columns.Add("id5");
    ds.Tables["Tmp_Pic"].Columns.Add("id6");
    ds.Tables["Tmp_Pic"].Columns.Add("cate1");
    ds.Tables["Tmp_Pic"].Columns.Add("cate2");
    ds.Tables["Tmp_Pic"].Columns.Add("cate3");
    ds.Tables["Tmp_Pic"].Columns.Add("cate4");
    ds.Tables["Tmp_Pic"].Columns.Add("cate5");
    ds.Tables["Tmp_Pic"].Columns.Add("cate6");
    ds.Tables.Add(dt);DataTable dt = ds.Tables["Pic_View"];  //简化操作
    for (int i=0;i<dt.Rows.Count;i=i+6)
    {
       try
       {
          DataRow myRow=ds.Tables["Tmp_Pic"].NewRow();
          myRow["id1"] = dt.Rows[i]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i]["Cate"].ToString();
          myRow["id1"] = dt.Rows[i+1]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i+1]["Cate"].ToString();
          myRow["id1"] = dt.Rows[i+2]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i+2]["Cate"].ToString();
          myRow["id1"] = dt.Rows[i+3]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i+3]["Cate"].ToString();
          myRow["id1"] = dt.Rows[i+4]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i+4]["Cate"].ToString();
          myRow["id1"] = dt.Rows[i+5]["ID"].ToString();
          myRow["cate1"] = dt.Rows[i+5]["Cate"].ToString();
          
          ds.Tables["Tmp_Pic"].Rows.Add(myRow);
          
       }
       catch
       {}
    }
      

  8.   

    不好意思,上面的有些错误,需要将 myRow["id1"],myRow["cate1"]分别修改为指向1-6之间的数字。
      

  9.   

    代码太乱,建议采用:
    DataTable.Clone();//复制表结构
    DataTable.Rows.Add(...);