你不应该用
objDataAdapter.Fill(ds,"Tmp_Pic");
来生成临时表。
应该用:
DataTable dt = new DataTable();
DataTable.TableName="Tmp_Pic";
ds.Tables["Tmp_Pic"].Columns.Add("id1");
//..更多字段
ds.Tables.Add(dt);
//....
objDataAdapter.Fill(ds,"Tmp_Pic");
来生成临时表。
应该用:
DataTable dt = new DataTable();
DataTable.TableName="Tmp_Pic";
ds.Tables["Tmp_Pic"].Columns.Add("id1");
//..更多字段
ds.Tables.Add(dt);
//....
异常详细信息: 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();??
{
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 处没有任何行。
myRow["id"] = i;
myRow["item"] = "item " + i.ToString();
myDataTable.Rows.Add(myRow);
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);
} }楼上的,不会写了,帮帮忙~
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
{}
}
DataTable.Clone();//复制表结构
DataTable.Rows.Add(...);