I am totally new in Dot Net and in Programming Field.
I have to Send Some Data from One Table in Email in one console app. It is working fine. I am doing this by retrieving Data into DataTable.
Now i have to insert same Data into Different Database Table.
So how i can do this. Please share a simple way.
(In DataTable data is coming by Single Select Query, So is there any way to solve this problem using this Select command with Insert command, Like Insert into Table Values (Seelct Command))
There are probably no easy ways to do it from the original DataTable (unless you decide to parse the original Select query and replace table name), so the simplest way is to just:
It will look something like(didn't actually test it, though)
private const String SelectDataTableTemplate = @"SELECT ... FROM {0}";
...
var originalDataTable = GetDataTable();
var copyOfDataTable = originalDataTable.Copy();
foreach(var row in copyOfDataTable.Rows)
{
row.AcceptChanges(); // sets DataRowState.Unchanged
row.SetAdded();
}
var dataAdapter = new OracleDataAdapter(
selectCommandText: String.Format(SelectDataTableTemplate, "AnotherTableName"),
selectConnection: _connection));
dataAdapter.Update(copyOfDataTable);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.