I have two DataTables. I simply wanna save one of them in the other and then change the column name on my "temporary table".
My problem is that everytime that I change the column name from one table, it is automatically changing in the other.
declaration:
public DataTable DataTablefromDataBaseFormDataType { get; private set; }
How do I get value for the first DataTable:
DataTablefromDataBaseFormDataType = ((FormProject)Fproject).DataTablefromDataBaseFormProject;
How do I copy and change column name:
DataTableUsedToPlotGraphTemp = DataTablefromDataBaseFormDataType;
DataTableUsedToPlotGraphTemp.Columns[column_to_use].ColumnName = "temp";
Rest of the code (if needed)
DataTableUsedToPlotGraphTemp = DataTablefromDataBaseFormDataType;
DataTableUsedToPlotGraphTemp.Columns[column_to_use].ColumnName = "temp";
// This point! - When I change DataTableUsedToPlotGraphTemp it is also changing //DataTableUsedToPlotGraphTemp
if (ReceiveStartDate == null && ReceiveEndDate == null)
{
ReceiveStartDate = DataTableUsedToPlotGraphTemp.Rows[0][4].ToString();
ReceiveEndDate = DataTableUsedToPlotGraphTemp.Rows[DataTableUsedToPlotGraphTemp.Rows.Count-1][4].ToString();
}
if (ReceiveNameFile != "All files")
{
string query = $"TIME_FORMATTED >='{ReceiveStartDate}' AND TIME_FORMATTED <='{ReceiveEndDate}'";
DataRow[] result = DataTableUsedToPlotGraphTemp.Select(query);
foreach (DataRow row in result)
{
//MessageBox.Show(row[0].ToString());
DataTableUsedToPlotGraph.ImportRow(row);
}
}
else
{
DataRow[] result = DataTablefromDataBaseFormDataType.Select("FILE_NAMES = '"+ ReceiveNameFile + "'");
foreach (DataRow row in result)
{
//MessageBox.Show(row[0].ToString());
DataTableUsedToPlotGraph.ImportRow(row);
}
}
}
I already debugged several times to see if it is happening in some other place of the code. The moment that it changes the column name, it changes for both DataTables.
Can anybody help me? Thank you.