none
Update row is not updating in dataAdapter RRS feed

  • Question

  • Hi All,

    In the below code i am inserting a new row and updating existing rows.

    it's working for insert but not for update. I checked in sql profiler, it's not generating query for update.

    Any one have any idea.

     

     public void Redistribute(DataTable dtPrizes)
            {
                try
                {
                    //Creating class instance to interact with the database
                    using (SqlConnection conn = new SqlConnection(connection))
                    {
                         SqlCommand cmd = new SqlCommand();
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "usp_GetUnAwardedPrize";
                        cmd.Connection = conn;
                        cmd.Parameters.AddWithValue("@TodayDate", DateTime.Now);
                        cmd.Parameters.AddWithValue("@TableId", 0);
                        cmd.Parameters.AddWithValue("@Flag", 1);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.SelectCommand = cmd;
                        SqlCommandBuilder Bldr = null;
                        Bldr = new SqlCommandBuilder(adapter);
                   
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();
                        adapter.Fill(ds);
                        dt = ds.Tables[0];
                        for (int count = 0; count < dtPrizes.Rows.Count; count++)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                if (Convert.ToInt32(dtPrizes.Rows[count]["pts_ID"]) == Convert.ToInt32(dt.Rows[i]["pts_ID"]))
                                {
                                    dt.DefaultView.RowFilter = "pts_ID = " + dtPrizes.Rows[count]["pts_ID"];
                                    dt.DefaultView[0]["ptt_Time1"] = dtPrizes.Rows[count]["ptt_Time1"];
                                    dt.DefaultView[0]["ptt_Time2"] = dtPrizes.Rows[count]["ptt_Time2"];
                                    dt.DefaultView[0]["ptt_ModifiedDate"] = dtPrizes.Rows[count]["ptt_ModifiedDate"];
                                    dt.DefaultView[0]["UserId"] = dtPrizes.Rows[count]["UsersId"];
                                    dt.AcceptChanges();
                                    dt.DefaultView.RowFilter = null;
                                    break;
                                }
                            }
                        }
                        DataRow dr = dt.NewRow();
                        dr[1] = DateTime.Now;
                        dt.Rows.Add(dr);
                       
                        adapter.Update(dt);

                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

     

    Thanks in advance..

    Thursday, February 3, 2011 12:34 PM

Answers

All replies