none
insert statement does not reflect in database RRS feed

  • Question

  • I am trying to insert data into my table whose primary key is auto increment. The problem i encounter is that anytime i perform the insert, it goes through and i can view it when my application is running but as soon as i stop debugging and i run again i dont see the data again. I also notice that the insertion i did does not show up in the database. Below is the code i am using:

     

    String name, type;
    name = txtname.Text;
    type = txttype.Text;

    int qtyToInt = Int32.Parse(txtqty.Text);
    decimal priceToInt = decimal.Parse(txtprice.Text);


    shopDataSet.stockRow newStockRow = shopDataSet1.stock.NewstockRow();


    newStockRow.name = name;
    newStockRow.type = type;
    newStockRow.quantity = qtyToInt;
    newStockRow.price = priceToInt;

    this.shopDataSet1.stock.Rows.Add(newStockRow);
    this.stockTableAdapter1.Update(this.shopDataSet1.stock);

    • Moved by SamAgain Friday, October 8, 2010 3:24 AM better fit (From:64-Bit .NET Framework Development.)
    Wednesday, October 6, 2010 6:10 PM

All replies

  • Did you check the stockTableAdapter1 configuration (the autogenerated code)? Specially its InsertCommand.
    Miha Markic [MVP C#] http://blog.rthand.com
    Tuesday, October 12, 2010 6:34 AM
  • How about runing your application without debugging (Ctrl + F5)? Does it happen only when debugging? Please try to refresh the table before viewing its data.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, October 13, 2010 6:32 AM
  • Out of curiosity, what would be the difference when debugging or not in this case?
    Miha Markic [MVP C#] http://blog.rthand.com
    Wednesday, October 13, 2010 6:33 AM
  • If you set a breakpoint on a line and attempt to step through the code, however, you stopped debugging during the session, that may result in some code be executed, while others not. In this case, since persisting data into database by calling Update(), if you stop debugging before calling it, no data will be persisted in database. If you start without debugging, this situation does not occur.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, October 13, 2010 6:54 AM
  • Ah, ok, checking the very basic mistakes.

    Miha Markic [MVP C#] http://blog.rthand.com
    Wednesday, October 13, 2010 8:02 AM