how to add new column in new DataTable But Erorr
private void LoadtoList()
{
SqlDataAdapter sa = new SqlDataAdapter("SELECT * FROM EmpSign", _constr);
dt = new DataTable("CCTVTable");
sa.Fill(dt);
dtpass = new DataTable("CCTVpassword");
SqlDataAdapter sa2 = new SqlDataAdapter("SELECT PASSWORD FROM Emp e WHERE e.EmpID IN ('f2123', 'f2124', 'f2126', 'rt015', 'f2133')",
ConfigurationManager.ConnectionStrings["SaraburiEmp"].ConnectionString);
sa2.Fill(dtpass);
DataColumn dc = new DataColumn();
dc = dtpass.Columns["password"];
dt.Columns.Add(dc);
}
Column ‘PASSWORD’ already belongs to
another DataTable. Description: An
unhandled exception occurred during
the execution of the current web
request. Please review the stack trace
for more information about the error
and where it originated in the code.Exception Details:
System.ArgumentException: Column
‘PASSWORD’ already belongs to another
DataTable.Source Error:
Line 1040: DataColumn dc = new DataColumn();
Line 1041: dc = dtpass.Columns["password"];
Line 1042: dt.Columns.Add(dc);
Line 1043: }
Line 1044:}
You have explanation in exception message: “Column ‘PASSWORD’ already belongs to another DataTable”
Which basically means that You cannot reuse this column. You have to create new one (similar to this password column) and then add it to table.