Results 1 to 2 of 2

Thread: [2.0] Please help...dataadapter not inserting records

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Unhappy [2.0] Please help...dataadapter not inserting records

    I am trying to use data adapter to insert records into a table. but for some reason, no records get inserted. The data base is oracle.

    DataGateway aDataGateway = new DataGateway();
    OracleConnection aMbsfas91Connection = aDataGateway.GetMbsFas91Connection();
    aMbsfas91Connection.Open();
    OracleDataAdapter adp = new OracleDataAdapter(sqlDataAdapter, aMbsfas91Connection);
    OracleCommand command = new OracleCommand(ssqlInsert, aMbsfas91Connection);command.CommandType = CommandType.Text;
    command.Parameters.Add("CUSIP", OracleType.VarChar, 20, "CUSIP");
    command.Parameters.Add("SEC_ID", OracleType.VarChar, 20, "SEC_ID");

    adp.InsertCommand = command;
    adp.Fill(aDataTableMbsDeals);
    adp.Update(aDataTableMbsDeals);
    aMbsfas91Connection.Close();

    No errors show up but the data doesn't get updated

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Please help...dataadapter not inserting records

    The problem is that all the DataRows in your DataTable have their RowState set to Unchanged, so when you call Update there are no new rows in the DataTable to insert. All the DataRows must have their RowState set to Added if they're to be inserted into a table.

    When you call Fill the DataAdapter will create all the DataRows and then add them to the DataTable, at which point their RowState is Added. At that point the default behaviour of the DataAdapter is to call the table's AcceptChanges method, which sets all the RowStates to Unchanged, then Fill returns.

    In order to override that default behaviour you have to set the AcceptChangesDuringFill property the DataAdapter to False.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width