Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   C# Updating changes back to SQl database (http://www.go4expert.com/forums/c-sharp-updating-changes-sql-database-t28590/)

markyjj 17Jun2012 01:30

C# Updating changes back to SQl database
 
Can someone please help me on this problem. I am trying to send the updated changes to the sql database when I remove a row. I use the delete method to delete the numbered row and then use the upate command to update the changes. However, when I reload the program all the rows are still showing again. Below is the current code I am using for forms 1 and 2. This has been giving me a headache for awhile now and any further help would be appreciated:

Code:

//Form1
 private void UpdateSavebtn_Click_1(object sender, System.EventArgs e)
        {
            Mcon.Open();
            UpdateVal = 1;
            if (UpdateVal == 0)
            {
                CurCol = dataGrid1.CurrentCell.ColumnNumber;
                CurRow = dataGrid1.CurrentCell.RowNumber;
                CellValue = dataGrid1[CurRow, CurCol].ToString();
                MessageBox.Show(CellValue.ToString());


                if (CellValue == "")
                {

                    MessageBox.Show("No Fields can be Blank - update failed");
                    Movset1.RejectChanges();
                    ImageMain();
                    CurRow = -1;
                    CurCol = -1;

                    Mcon.Close();
                    return;

                }
                CellValue = dataGrid1[CurRow, CurCol].ToString();
                CurRow = -1;
                CurCol = -1;
            }

         
            MovAdapt.UpdateCommand = cb.GetUpdateCommand();
            MovAdapt.Update(Movset1.Tables[0]);
            Movset1.AcceptChanges();
           

            MessageBox.Show("New movie added");

            Mcon.Close();
            UpdateVal = 0;

            dataGrid1.RowHeadersVisible = true;
        }

Code:


 private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show(" Please enter a title to be deleted ");
                return;           
            }
         


              DSMethod();
              Dv2 = new DataView(ds2.Tables[0]);
              F1.dataGrid1.DataSource = Dv2;
              Dv2.RowFilter = "Title ='" + textBox1.Text + "'";

              if (Dv2.Count < 1)
              {
                  MessageBox.Show("Movie does not exist in MovieBase, please try again");
                  return;
              }
              else
              {
               
                  int rownum = (F1.dataGrid1.CurrentCell.RowNumber);
                  Dv2.Delete(rownum);

                  ds2.AcceptChanges();
                  //MovAdapt.UpdateCommand = cb.GetUpdateCommand();
                  //MovAdapt.Update(Movset1.Tables[0]);
                 
                  this.Hide();
                         
                    //Dv2.Table.Rows.Remove(Dv2.Table.Rows.current)
                 
                  MessageBox.Show("Movie has been deleted");
                 
              }



All times are GMT +5.5. The time now is 13:36.