private void btnUpdate_Click(object sender, EventArgs e)
{
SqlDataAdapter DA = new SqlDataAdapter(" select * FROM TblVendorsData", MDIParent1.cn);
DataSet DS = new DataSet();
SqlCommand CMD = new SqlCommand();
string strupdate = "Update TblVendorsData SET ";
if (dataGridView1.CurrentRow.Cells[1].Value.ToString() != CompanyName)
{
strupdate += " CompanyName = '" + dataGridView1.CurrentRow.Cells[1].Value.ToString() + "' " + ",";
}
if (dataGridView1.CurrentRow.Cells[2].Value.ToString() != F_CompanyName)
{
strupdate += " F_CompanyName = '" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "' " + ",";
strupdate = strupdate.Remove(strupdate.Length - 1);
strupdate = strupdate + " where ID = " + dataGridView1.CurrentRow.Cells[0].Value.ToString();
CMD.CommandText = strupdate;
CMD.CommandType = CommandType.Text;
CMD.Connection = MDIParent1.cn;
try
{
CMD.Connection.Open();
CMD.ExecuteNonQuery();
CMD.Connection.Close();
MessageBox.Show("Update is done");
}
catch (Exception)
{
MessageBox.Show("Don't Update");
}
}
}
ممنونم آقای ابراهیمی
این کد برنامه س البته تعداد فیلدهام خیلی بیشتره
توسط
daryaazad
(109 امتیاز)
●2 ●6