将完整数据从一个数据表复制到另一个数据表并绑定到Gridview问题 [英] Copy of complete data from one data table to another and binding to Gridview Problem
本文介绍了将完整数据从一个数据表复制到另一个数据表并绑定到Gridview问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
当我想将一个数据表项复制到另一个数据表项时,我的问题就是这个问题,但它在运行时没有绑定到gridview我的代码在下面
Hi
My problem is this when I want to copy one data table items to another it copies but it does not bind to gridview on run time my code is below
foreach (string chk in City)
{
DataTable temps = new DataTable();
foreach (string skls in keyskills)
{
cmd = new SqlCommand("Mat_Part2", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Keys", SqlDbType.VarChar).Value = skls;
cmd.Parameters.Add("@HighQualification", SqlDbType.VarChar).Value = HighQualification;
cmd.Parameters.Add("@Exp", SqlDbType.Int).Value = TotalExpYear;
cmd.Parameters.Add("@Location", SqlDbType.VarChar).Value = chk;
da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
temps = dt.Clone();
//DataRow dRow;
//foreach(DataRow row in dt.Rows)
//{
// dRow = temps.NewRow();
// dRow.ItemArray = row .ItemArray;
// temps.Rows.Add(dRow);
//}
temps = dt.Copy();
temps.AcceptChanges();
}
mainTable = temps.Clone();
mainTable = temps.Copy();
mainTable.AcceptChanges();
//DataRow dRow1;
//foreach (DataRow row in temps.Rows)
//{
// mainTable.ImportRow(row);
// //dRow1 = temps.NewRow();
// //dRow1.ItemArray = row.ItemArray;
// //mainTable.Rows.Add(dRow1);
//}
}
GridView1.DataSource = mainTable;
GridView1.DataBind();
这个没有任何例外。
this no gives any exception.
推荐答案
这个解决方案
int flg = 0,flg1=0;
foreach (string chk in City)
{
foreach (string skls in keyskills)
{
cmd = new SqlCommand("Mat_Part2", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Keys", SqlDbType.VarChar).Value = skls;
cmd.Parameters.Add("@HighQualification", SqlDbType.VarChar).Value = HighQualification;
cmd.Parameters.Add("@Exp", SqlDbType.Int).Value = TotalExpYear;
cmd.Parameters.Add("@Location", SqlDbType.VarChar).Value = chk;
da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (flg == 0)
{
mainTable = dt.Clone();
flg++;
}
DataRow dRow;
foreach (DataRow row in dt.Rows)
{
if (flg1 == 0)
{
mainTable = dt.Copy();
flg1++;
}
int xts = mainTable.Rows.Count;
for (int cv = 0; cv < xts; cv++)
{
dRow = mainTable.NewRow();
for (int gh = 0; gh < dt.Rows.Count; gh++)
{
int yst = Convert.ToInt32(dt.Rows[gh]["Id"].ToString());
int pretemp = 0;
int flag = 0;
while (pretemp < mainTable.Rows.Count)
{
int xst = Convert.ToInt32(mainTable.Rows[pretemp]["Id"].ToString());
if (xst == yst)
{
flag = 1;
}
pretemp++;
}
if (flag == 0)
{
dRow.ItemArray = row.ItemArray;
mainTable.Rows.Add(dRow);
}
}
}
}
}
}
这篇关于将完整数据从一个数据表复制到另一个数据表并绑定到Gridview问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文