1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Updating changes back to SQl database

Discussion in 'C#' started by markyjj, Jun 16, 2012.

  1. markyjj

    markyjj New Member

    Joined:
    Dec 7, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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");
                       
                   }
                  
    
     

Share This Page