1.

Solve : C# Updating changes back to SQl database?

Answer»

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 upadte 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: [Select]
//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: [Select]
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");

}

Try updating the whole DataSet, as in

Code: [Select] MovAdapt.Update(Movset1);



Discussion

No Comment Found