thenndral

thenndral

  • NA
  • 45
  • 30.8k

Multi table - insert through datatable.

Oct 11 2011 1:04 PM

Hi,

I'm using C# 2008
DB - oracle11G

Actually i'm trying to insert data into multiple table. first insert statement works well, but 2nd insert statement not working and error also not coming.what and where goes wrong. please help.

here i give the code. could you give me some guidance.

private void btnSave_Click(object sender, EventArgs e)
{
connectionString = "User Id=tom;Password=pwd4tom;Data Source=remote_oracle";
cn = new OracleConnection(connectionString);
OracleDataAdapter editAdapter ;
OracleCommand insertCmd;
insertCmd = new OracleCommand();
insertCmd.CommandText = "INSERT INTO CUSTOMERS (CUSTOMERID, COMPANYNAME, CONTACTNAME, COUNTRY) values(:CUSTOMERID, :COMPANYNAME, :CONTACTNAME, :COUNTRY)";

insertCmd.Parameters.Add("CUSTOMERID", OracleDbType.Varchar2, 10, "CUSTOMERID");

insertCmd.Parameters.Add("COMPANYNAME", OracleDbType.Varchar2, 10, "COMPANYNAME");

insertCmd.Parameters.Add("CONTACTNAME", OracleDbType.Varchar2, 10, "CONTACTNAME");

insertCmd.Parameters.Add("COUNTRY", OracleDbType.Varchar2, 10, "COUNTRY");

insertCmd.Connection = cn;
editAdapter = new OracleDataAdapter();
editAdapter.InsertCommand = insertCmd
editAdapter.TableMappings.Add("Table", "CUSTOMERS");
editAdapter.TableMappings["Table"].ColumnMappings.Add("CUSTOMERID", "CUSTOMERID");
editAdapter.TableMappings["Table"].ColumnMappings.Add("COMPANYNAME", "COMPANYNAME");
editAdapter.TableMappings["Table"].ColumnMappings.Add("CONTACTNAME", "CONTACTNAME");
editAdapter.TableMappings["Table"].ColumnMappings.Add("COUNTRY", "COUNTRY");
editAdapter.Update(empTbl); /// this table data save perfectly
//CUST_DETAILS.CD_ID, CUST_DETAILS.CUST_ID, CUST_DETAILS.CUST_CELL, CUST_DETAILS.CUST_NAME
insertCmd.CommandText = "INSERT INTO CUST_DETAILS (CD_ID, CUST_ID, CUST_CELL, CUST_NAME) values(:CD_ID, :CUST_ID, :CUST_CELL, :CUST_NAME)";
insertCmd.Parameters.Add("CD_ID", OracleDbType.Varchar2, 10, "CD_ID");

insertCmd.Parameters.Add("CUST_ID", OracleDbType.Varchar2, 10, "CUST_ID");

insertCmd.Parameters.Add("CUST_CELL", OracleDbType.Varchar2, 10, "CUST_CELL");

insertCmd.Parameters.Add("CUST_NAME", OracleDbType.Varchar2, 10, "CUST_NAME");

insertCmd.Connection = cn;
editAdapter = new OracleDataAdapter();
editAdapter.InsertCommand = insertCmd;
editAdapter.TableMappings.Add("Table1", "CUST_DETAILS");
editAdapter.TableMappings["Table1"].ColumnMappings.Add("CD_ID", "CD_ID");
editAdapter.TableMappings["Table1"].ColumnMappings.Add("CUST_ID", "CUST_ID");
editAdapter.TableMappings["Table1"].ColumnMappings.Add("CUST_CELL", "CUST_CELL");
editAdapter.TableMappings["Table1"].ColumnMappings.Add("CUST_NAME", "CUST_NAME");
editAdapter.Update(empTbl); // no error but not save in table.
}
thanks,
thenndral.

Answers (4)