+2 امتیاز
با سلام
دوستان من وقتی مقادیر یه سطر از دیتا گرید را ویرایش میکنم و بعد با دکمه ویرایش اون مقادیرو به کلاس آپدیت میفرستم در آخر موفقیت آمیز هست عمل ولی مقادیر قبلی همین سطر از دیتاگرید دوباره ویرایش میشن.وقتی ام که چندتا تکس گذاشتم و مقادیر رو داخلش ریختم و بعد تکس باکس ها رو فرستادم که بازم فایده نداشت!

حتی به جای ویرایش دستور اینسرتم زدم که اونم باز با مقادیر قبلی اینزرت میکرد

سلام دوست خوبم لطف کنید کدتون رو هم قرار بدین . 

توسط (6,145 امتیاز) 5 11 116

2 پاسخ

+2 امتیاز
سلام اون طور که متوجه شدم شما احتمالا جایی اطلاعات بانک رو نگه میدارید بعد با اون اطلاعات اطلاعات جدید رو میفرستید یا تابع شما Static هست که اینم خودش موجب میشه افزونگی پیش بیاد
+2 امتیاز
سلام

درست منظور رو نرسوندی همیشه آپدیت براساس کلید انجام میشه

به فرض اگر سطر 1 رو انتخاب کنم مقادیر سطر یک ویرایش میشه .

این مشکل رو حلش کردم.الان مشکل بزرگ اینه که وقتی اپدیت میشه مقادیری که در دیتاگرید میدم ذخیره نمیشه و همون مقادیر قبلی ذخیره میشه..تو برنامه تک لایه قبلا با یه دیتا اداپتر و دیتا تیبل و یه کامند بیلدر حل میشد ولی الان تو معماری سه لایه که از همین سایت گرفتم گیج شدم با این کد قبلا حل میشد: داخل دکمه ویراش فقط همینا مینوشتم دیگه هم حتی نیاز به اندکس و ایناشم نبود:

Sqlcommandbuilder scb=new sqlcommandbuilder (dat ( Dat= new dataadapter)dt (

 

توسط (124 امتیاز) 1 14
در کل معماری سه لایه با تک لایه در تعریف کردن  متد ها فرق میکنه حالا زمانی که  روی آپدیت کلیک می کنی شما سه لایه داری و هر سه لایه رو باید فراخوانی کنی .

به احتمال زیاد زمانی کد رو سه لایه  کردی دستورات رو جابه جا کردی .
توسط (607 امتیاز) 1 5 29
آقا این کد ویرایش من داخل باتن :

if (this.dataGridViewX1.Rows.Count > 0)
            {
               // int personelIndex = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
                if (this.buttonItem6.Text == "ویرایش")
                {

                    dataGridViewX1.ReadOnly = false;
                    dataGridViewX1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
                   

                    this.buttonItem6.Text = "ثبت ویرایش";
                }
                else
                {
                    

                    try
                    {

                
                        
                        //string tarikh_ma = "";
                        //int naghdi_ma = 0;
                        //int pos_ma = 0;
                        //int dakhl_ma = 0;
                        //int hazine_ma = 0;
                        //int kole_forosh_ma = 0;
                        //int mojodi_sandogh_ma = 0;
                        //int variz_ma = 0;
                        //string sharhe_variz_ma = "";
                        //ribbonBar12.Text = this.dataGridViewX1.CurrentRow.Cells[9].Value.ToString();
                        //sharhe_variz_ma = this.dataGridViewX1.CurrentRow.Cells[9].Value.ToString();
                        //tarikh_ma = this.dataGridViewX1.CurrentRow.Cells[1].Value.ToString();
                        //naghdi_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[2].Value.ToString());
                        //pos_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[3].Value.ToString());
                        //dakhl_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[4].Value.ToString());
                        //hazine_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[5].Value.ToString());
                        //kole_forosh_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[6].Value.ToString());
                        //mojodi_sandogh_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[7].Value.ToString());
                        //variz_ma = Convert.ToInt32(this.dataGridViewX1.CurrentRow.Cells[8].Value.ToString());
                          
                        //    textBox3.Text = tarikh_ma;
                        //    textBox4.Text = Convert.ToString(naghdi_ma );
                        //    textBox5.Text = Convert.ToString(pos_ma );
                        //    textBox6.Text = Convert.ToString(dakhl_ma );
                        //    textBox7.Text = Convert.ToString(hazine_ma );
                        //    textBox8.Text = Convert.ToString(kole_forosh_ma );
                        //    textBox9.Text = Convert.ToString(mojodi_sandogh_ma );
                        //    textBox10.Text = Convert.ToString(variz_ma );
                        //    textBox11.Text = sharhe_variz_ma;

                        //    DataEntityLayer.modiriat_asli mupdate = new DataEntityLayer.modiriat_asli(this.textBox3.Text.Trim(),
                        //                                                                                Convert.ToInt32(this.textBox4.Text.Trim()), Convert.ToInt32(this.textBox5.Text.Trim()),
                        //                                                                                Convert.ToInt32(this.textBox6.Text.Trim()), Convert.ToInt32(this.textBox7.Text.Trim()), Convert.ToInt32(this.textBox8.Text.Trim()),
                        //                                                                                Convert.ToInt32(this.textBox9.Text.Trim()), Convert.ToInt32(this.textBox10.Text.Trim()),
                        //                                                                                this.textBox11.Text.Trim());
                        //    BusinessLogicLayer.modiriat_asli bma = new BusinessLogicLayer.modiriat_asli();
                        //    bma.Update(mupdate,personelIndex );
                        //    MessageBox.Show("با موفقیت ویرایش شد");
                        //    this.dataGridViewX1.DataSource = bma.select_m_asli();
                     }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        this.buttonItem6.Text = "ویرایش";
                        dataGridViewX1.ReadOnly = true;
                        
                    }
                }
            }
توسط (124 امتیاز) 1 14
اینم کد لایه لاجیک:

 //******class virayeshe etelaat*******
 //   public void Update(DataEntityLayer.modiriat_asli  m_asli_toupdate,int index2)
 //  {
 //      if (
 //          !string.IsNullOrEmpty(m_asli_toupdate.tarikh) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.naghdi)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.pos)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.dakhl)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.hazine)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.kole_forosh)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.mojodi_sandogh)) &&
 //          !string.IsNullOrEmpty(Convert.ToString(m_asli_toupdate.variz)) &&
 //          !string.IsNullOrEmpty(m_asli_toupdate.sharhe_variz))
 //      {
 //          try
 //          {
 //             DataAccessLayer.modiriat_asli   dalm_asli= new DataAccessLayer.modiriat_asli ();
 //             dalm_asli.Update_m_asli(m_asli_toupdate,index2);
 //        }
 //        catch (Exception ex)
 //        {
 //            throw new Exception("خطا در ویرایش اطلاعات");
 //        }
 //    }
 //    else
 //    {
 //        throw new Exception("لطفا تمامی اطلاعات را وارد نمایید");
 //    }
 //}
توسط (124 امتیاز) 1 14
اینم کد لایه دیتا اکسس :

   public void Update_m_asli(DataEntityLayer.modiriat_asli m_asli_ToUpdate)
   {
       //string updateQuery = "UPDATE m_asli SET tarikh=@tarikh,naghdi=@naghdi,pos=@pos,dakhl=@dakhl,hazine=@hazine,kole_forosh=@kole_forosh,"+
       //                      "mojodi_sandogh=@mojodi_sandogh,variz=@variz,sharhe_variz=@sharhe_variz WHERE ID=@ID";
       //OleDbCommand  updateCommand = new OleDbCommand (updateQuery, this.databaseconnection );
       //updateCommand.Parameters.AddWithValue("@ID", index );
       //updateCommand.Parameters.AddWithValue("@tarikh", m_asli_ToUpdate.tarikh );
       //updateCommand.Parameters.AddWithValue("@naghdi", m_asli_ToUpdate.naghdi );
       //updateCommand.Parameters.AddWithValue("@pos", m_asli_ToUpdate.pos);
       //updateCommand.Parameters.AddWithValue("@dakhl", m_asli_ToUpdate.dakhl );
       //updateCommand.Parameters.AddWithValue("@hazine", m_asli_ToUpdate.hazine);
       //updateCommand.Parameters.AddWithValue("@kole_forosh", m_asli_ToUpdate.kole_forosh);
       //updateCommand.Parameters.AddWithValue("@mojodi_sandogh", m_asli_ToUpdate.mojodi_sandogh);
       //updateCommand.Parameters.AddWithValue("@variz", m_asli_ToUpdate.variz);
       //updateCommand.Parameters.AddWithValue("@sharhe_variz", m_asli_ToUpdate.sharhe_variz);
       ////DataTable dt = new DataTable();
       //OleDbDataAdapter oda = new OleDbDataAdapter();
       //     OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
      
       //oda.Update(dt);

       try
       {

          
      }
      catch (Exception ex)
      {
          throw ex;
      }
      finally
      {
         this.databaseconnection.Close();
      }
  }
توسط (124 امتیاز) 1 14
من دقیقا وقتی رشته کوئری رو با اینسرت عوض می کنم جواب میده و یه سطر جدید با مقادیری که ویرایش کردم اضافه میکنه و فقط تو آپدیت این مشکل هست
توسط (124 امتیاز) 1 14
سوال جدید

2,337 سوال

2,871 پاسخ

3,725 دیدگاه

3,921 کاربر

دسته بندی ها

...