none
Iam trying to insert these datas in sql, but it is not working RRS feed

  • Question

  •  OrderDataSet ds = newOrderDataSet();
                OrderDataSet.OrderRow r =ordertable.NewOrderRow();

     r.OrderNo = Convert.ToInt64(textBoxOrderNo.Text);

              
                r.OrderAmount = Convert.ToDecimal(textBoxTotal.Text);

               ordertable.Rows.Add(r);
                ds.Tables.Add(ordertable);


    • Edited by RAGU DEVA Monday, December 8, 2014 5:49 AM
    • Moved by Fred BaoModerator Tuesday, December 9, 2014 2:47 AM Move to a more appropriate forum
    Monday, December 8, 2014 5:25 AM

Answers

  • Hello RAGU,

    It seems that you are using the Strongly Typed DataSets, do you use the Adapter to update the DataSet/DataTable object as below?

    da.Adapter.Update(Your DataSet/DataTable object);

    i think this line “ds.Tables.Add(ordertable);” is not necessarily in your proivded code becuase in my test it causes a problem that the DataSet object contains two Order tables and one is empty so even you call the Update method, it still does not insert the record to database, you could use its third overwrite method which could accept a DataTable directly as code i post.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, December 9, 2014 3:08 AM
    Moderator

All replies

  • I need to see your ordertable class.  Here is an example of adding rows

                DataTable dt = new DataTable();
                DataRow dr = null;
                dt.Columns.Add("col 1", typeof(int));
                dt.Columns.Add("col 2", typeof(string));
    
                //method 1
                dr = dt.Rows.Add();
                dr[0] = 123;
    
                //method 2
                dt.Rows.Add(new object[] { 1, "abc" });


    jdweng

    Monday, December 8, 2014 9:01 AM
  • Hello RAGU,

    It seems that you are using the Strongly Typed DataSets, do you use the Adapter to update the DataSet/DataTable object as below?

    da.Adapter.Update(Your DataSet/DataTable object);

    i think this line “ds.Tables.Add(ordertable);” is not necessarily in your proivded code becuase in my test it causes a problem that the DataSet object contains two Order tables and one is empty so even you call the Update method, it still does not insert the record to database, you could use its third overwrite method which could accept a DataTable directly as code i post.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, December 9, 2014 3:08 AM
    Moderator
  • you can try to change your code to

    OrderDataSet ds = new OrderDataSet();

    OrderDataSet.OrderRow r = ds.ordertable.NewOrderRow();

     r.OrderNo = Convert.ToInt64(textBoxOrderNo.Text);
            
     r.OrderAmount = Convert.ToDecimal(textBoxTotal.Text);

     ds.ordertable.Rows.Add(r);

    Wednesday, December 10, 2014 3:34 PM