Most common ADO.NET error of all time :
- Remove the line that calls AcceptChanges on the DataTable.
Another Tip: You don't need to manually open and close connections
when using a DataAdapter.
On Nov 9, 7:00 am, Dickery1 <[EMAIL PROTECTED]> wrote:
> i dont know why this code is not saving the data that i am trying to
> insert. appreciate any help
> MySqlConnection myConnection = new MySqlConnection(CONN);
> MySqlDataAdapter myDataAdapter = new
> MySqlDataAdapter(QUERY, myConnection);
> DataTable dt = new DataTable();
>
> //Open connection
> myConnection.Open();
>
> try
> {
> //Fill dataset
> myDataAdapter.Fill(dt);
>
> //Close connection
> myConnection.Close();
> DataTable dtPortfolios = dt;
> DataRow newRow = dtPortfolios.NewRow();
> newRow["symbol"] = "errwerew";
> newRow["quantity"] = 2;
> newRow["cost"] = 4;
> newRow["created_at"] = DateTime.Now;
> dtPortfolios.Rows.Add(newRow);
> dtPortfolios.AcceptChanges();
> myDataAdapter.Update(dt);
>
> }
> catch (Exception ex)
> {
>
> //Close connection
> myConnection.Close();
>
> throw ex;
>
> }