datatable
-
i want to fill one datatable by another datatable but its not working. so plz help in solving this.
-
i want to fill one datatable by another datatable but its not working. so plz help in solving this.
Good Mornig Malik1122 We cant know what is the Problem until we see the code, another thing that can be easly done on the SQL. e.g
INSERT INTO TABLE2
SELECT COL1,COL2 FROM TABLE1
WHERE COL1 IS NOT NULLAlways try to keep the sql side in SQl , because these things can be achieve at ease that side than trying to loop through a datatable. Please explain clearly what is your problem.
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
int colm = 0; if (objBUS.busDataSet.Tables["tblSwapedColumns"].Columns.Count > 0) { for (int X = 0; X < objBUS.busDataSet.Tables["tblSwapedColumns"].Columns.Count; X++) { if (objBUS.busDataSet.Tables["tblSwapedColumns"].Columns[X].ToString() == objBUS.busDataSet.Tables["tbl"].Columns[colm].ToString()) { if (colm == 0) { for (int Q = 0; Q < objBUS.busDataSet.Tables["tbl"].Rows.Count; Q++) { objBUS.busDataSet.Tables["tblSwapedColumns"].Rows.Clear(); DataRow DRow = objBUS.tblSwapedColumns.NewRow(); DRow[objBUS.busDataSet.Tables["tblSwapedColumns"].Columns[X]] = objBUS.busDataSet.Tables["tbl"].Rows[Q][colm].ToString();//here code //give exception "Column 'FIRST NAME' does not belong to table tblSwapedColumns" //'FIRST NAME' is the column name which is previously present in the table. objBUS.tblSwapedColumns.Rows.Add(DRow); } colm++; } else { for (int Q = 0; Q < objBUS.busDataSet.Tables["tbl"].Rows.Count; Q++) { objBUS.busDataSet.Tables["tblSwapedColumns"].Rows[X][Q] = objBUS.busDataSet.Tables["tbl"].Rows[X][colm].ToString(); objBUS.busDataSet.Tables["tblSwapedColumns"].AcceptChanges(); } colm++; } } } }
-
Good Mornig Malik1122 We cant know what is the Problem until we see the code, another thing that can be easly done on the SQL. e.g
INSERT INTO TABLE2
SELECT COL1,COL2 FROM TABLE1
WHERE COL1 IS NOT NULLAlways try to keep the sql side in SQl , because these things can be achieve at ease that side than trying to loop through a datatable. Please explain clearly what is your problem.
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
Can i see the Structure of tblSwapedColumns ?
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
Can i see the Structure of tblSwapedColumns ?
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
The column of 'tbl' are 1. FIRST NAME 2. LAST NAME 3. DATE OF BIRTH 4. AGE 5. GENDER And that of 'tblSwapedColumns' are 1. GENDER 2. DATE OF BIRTH 3. AGE 4. LAST NAME 5. FIRST NAME
The Problem might be the names of your Columns in SQl it would be fine. Try not to name your Field names with Spaces , when Defining your Column names use something like th First_Name or Firstname Last_Name or LastName please Fix that and try to run your code again
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
i want to fill one datatable by another datatable but its not working. so plz help in solving this.
-
The Problem might be the names of your Columns in SQl it would be fine. Try not to name your Field names with Spaces , when Defining your Column names use something like th First_Name or Firstname Last_Name or LastName please Fix that and try to run your code again
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
i want to fill one datatable by another datatable but its not working. so plz help in solving this.
Hi Malik. Just Assign one table to other like DataTable dt=datatable; if one table already contains some records and you don't want to loss that then use the following code.
//copy tbl1 to tbl2
public DataTable MergTables(DataTable tbl1, DataTable tbl2)
{
if (tbl1.Rows.Count > 0)
{
foreach (DataRow row in tbl1.Rows)
{
DataRow newrow = tbl2.NewRow();
newrow["Col1"] = row["Col1"].ToString();
newrow["Col2"] = row["Col2"].ToString();
newrow["Col3"] = row["Col3"].ToString();
tbl2.Rows.Add(newrow);
tbl2.AcceptChanges();} } return tbl2; }
-
int colm = 0; if (objBUS.busDataSet.Tables["tblSwapedColumns"].Columns.Count > 0) { for (int X = 0; X < objBUS.busDataSet.Tables["tblSwapedColumns"].Columns.Count; X++) { if (objBUS.busDataSet.Tables["tblSwapedColumns"].Columns[X].ToString() == objBUS.busDataSet.Tables["tbl"].Columns[colm].ToString()) { if (colm == 0) { for (int Q = 0; Q < objBUS.busDataSet.Tables["tbl"].Rows.Count; Q++) { objBUS.busDataSet.Tables["tblSwapedColumns"].Rows.Clear(); DataRow DRow = objBUS.tblSwapedColumns.NewRow(); DRow[objBUS.busDataSet.Tables["tblSwapedColumns"].Columns[X]] = objBUS.busDataSet.Tables["tbl"].Rows[Q][colm].ToString();//here code //give exception "Column 'FIRST NAME' does not belong to table tblSwapedColumns" //'FIRST NAME' is the column name which is previously present in the table. objBUS.tblSwapedColumns.Rows.Add(DRow); } colm++; } else { for (int Q = 0; Q < objBUS.busDataSet.Tables["tbl"].Rows.Count; Q++) { objBUS.busDataSet.Tables["tblSwapedColumns"].Rows[X][Q] = objBUS.busDataSet.Tables["tbl"].Rows[X][colm].ToString(); objBUS.busDataSet.Tables["tblSwapedColumns"].AcceptChanges(); } colm++; } } } }
-
Hi Malik. Just Assign one table to other like DataTable dt=datatable; if one table already contains some records and you don't want to loss that then use the following code.
//copy tbl1 to tbl2
public DataTable MergTables(DataTable tbl1, DataTable tbl2)
{
if (tbl1.Rows.Count > 0)
{
foreach (DataRow row in tbl1.Rows)
{
DataRow newrow = tbl2.NewRow();
newrow["Col1"] = row["Col1"].ToString();
newrow["Col2"] = row["Col2"].ToString();
newrow["Col3"] = row["Col3"].ToString();
tbl2.Rows.Add(newrow);
tbl2.AcceptChanges();} } return tbl2; }
-
The Problem might be the names of your Columns in SQl it would be fine. Try not to name your Field names with Spaces , when Defining your Column names use something like th First_Name or Firstname Last_Name or LastName please Fix that and try to run your code again
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
You welcome.
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/