Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

how to solve this erro : "A column named 'Rowno' already belongs to this DataTable"

$
0
0

hi i am merging value in datatable inside  foreach.  foreach works using id iteration. id = 1,2,3,4

foreach (ListItem list in chek.Items)
{

qlConnection pubconncheck = new SqlConnection(connstr);

SqlCommand cmd4 = new SqlCommand("select * from table where id = id_value);


SqlDataAdapter sp_adap = new SqlDataAdapter(cmd4);

DataTable chktb1 = new DataTable();
DataTable sp_dt = new DataTable();
sp_adap.Fill(sp_dt);
DataColumn column = new DataColumn("Rowno");
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;


chktb1.Columns.Add(column);

chktb1.Merge(sp_dt);


}

here first iteration works correctly. 

when it goes to second iteration i am getting this error : "A column named 'Rowno' already belongs to this DataTable".

I know why i am getting this error. while first iteration rowno is assinged as name. so when the second iteration go, this line "chktb1.Columns.Add(column);" throws that error as already the name was existing. i tried to solve as much as possible. but still i am getting problem. how to solve that problem. help needed.


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>