Monday, February 6, 2012

Row already belongs to another table

November 1, 2009 by · Leave a Comment 

When copying a row from one datatable to another you might get the error "this row already belongs to another table". Typically you might write code like this: string sConnString = ConfigurationManager.ConnectionStrings["NorthwindConn"].ConnectionString; DataSet ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(sConnString,CommandType.Text, "select * from suppliers order by supplierid"); int nRowCount = 0; DataTable dt = ds.Tables[0];DataTable dt2 = dt.Clone(); dt2.Clear(); [...]

Delete duplicate rows from table

November 1, 2009 by · 1 Comment 

In the above line we are inserting all the distinct row of the "EmployeeTable" to another table "Emp_Temp_Table" (Emp_Temp_Table will create automatically when you use the above query.) Actuall the above query create clone of EmployeeTable and insert all the distinct row inside the Clone Table (Emp_Temp_Table). drop table EmployeeTable sp_rename ‘Emp_Temp_Table’,EmployeeTable’ Then Delete the [...]