Hi @Josh S ,
You can refer to the following code.
using System.Data;
using System.Data.OleDb;
class Program
{
static void Main(string[] args)
{
string connectionString = "your_connection_string_here";
string selectCommand = "SELECT * FROM tblA";
using (OleDbConnection con = new OleDbConnection(connectionString))
{
using (OleDbDataAdapter dA = new OleDbDataAdapter(selectCommand, con))
{
DataSet dS = new DataSet();
DataTable dT = new DataTable();
// Fill the DataSet and DataTable
dA.Fill(dS);
dA.Fill(dT);
// Create a new select command
string strSelectTblA = "SELECT * FROM tbl_A";
OleDbDataAdapter dAdpt = new OleDbDataAdapter(strSelectTblA, con);
dAdpt.SelectCommand = new OleDbCommand(strSelectTblA, con);
// Add table mapping
dAdpt.TableMappings.Add("tbl_A", "tbl_A");
// Get insert command
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dAdpt);
OleDbCommand insertCommand = cmdBuilder.GetInsertCommand();
// Fill DataSet and DataTable
DataSet myDs = new DataSet();
dAdpt.Fill(myDs, "tbl_A");
DataTable myDt = new DataTable();
dAdpt.Fill(myDt);
// Add rows to DataSet
foreach (DataRow thisRow in myDt.Rows)
{
int RecNumber = myDt.Rows.IndexOf(thisRow) + 1;
DataRow tbl_A_Row = myDs.Tables["tbl_A"].NewRow();
tbl_A_Row.BeginEdit();
tbl_A_Row["RecNumber"] = RecNumber;
// Set other column values here
tbl_A_Row.EndEdit();
myDs.Tables["tbl_A"].Rows.Add(tbl_A_Row);
}
}
}
}
}
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.