المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : update:Edit datagridview



C# Programming
08-12-2009, 11:24 AM
Hello.
more detail:

I have a datagridview and i written save code for it ,but when i change the fied of datagridview Rows for test my save code,after i chenge field(immediately)and i press Eter key ,that row i chenged it be removed from datagridview,before i press save button .So i cann't save the changes.
But if i change the last row of datagridview this row not remove ,and i can save it exactly.
I do not know why other rows after change to remove.?

this is my save code:
private void myBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{

SqlConnection objconnection = new SqlConnection(myconnection_string);
int i, idj, tedad, ghimat;
for (i = 0; i < myDataGridView.RowCount; i++)
{
idj = int.Parse((myDataGridView.Rows[i].Cells[0].Value).ToString());
tedad = int.Parse((myDataGridView.Rows[i].Cells[1].Value).ToString());

SqlCommand mycommand = new SqlCommand("UPDATE table1 SET tedad = @tedad WHERE (fid=@fid AND idj = @idj AND tedad ='0')", objconnection);
mycommand.Parameters.AddWithValue("@fid", fid);
mycommand.Parameters.AddWithValue("@idj", idj);
mycommand.Parameters.AddWithValue("@tedad", tedad);
objconnection.Open();
mycommand.ExecuteNonQuery();
objconnection.Close();
}
}