نوشته شده توسط
Ghaem66
میشه کد رو کامل قرار بدین؟
راستی اصلا گرید هیچ مقداری داره؟
مقدار داره اینم کد
for (int i = 0; i < dataGridView9.Rows.Count; i++)
{
try
{
SqlCommand com1 = new SqlCommand("insert into trfactor(namekala,codekala,ghvahed,codefactor,teda d) values(@a,@b,@c,@d,@e)", con);
com1.Parameters.AddWithValue("@a", dataGridView9.Rows[i].Cells[0].Value.ToString());
//check kardane vojoode code kala va jame kala
try
{
string sql2 = string.Format("SELECT * FROM tkala where codekala =" + Convert.ToInt32(dataGridView9.Rows[i].Cells[1].Value));
SqlDataAdapter da2 = new SqlDataAdapter(sql2, con);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "tkala");
DataTable db2 = ds2.Tables["tkala"];
if (db2.Rows.Count == 0)
{
con.Close();
goto next1;
}
//kam kardane meghdare mojoodi kala az meghdare darkhasti kala
if (cnoefa4.Text == "فروش")
{
con.Open();
SqlCommand cmd4;
try
{
cmd4 = con.CreateCommand();
cmd4.CommandText = "update tkala set tedad=@a where codekala=" + dataGridView9.Rows[i].Cells[1].Value;
cmd4.Parameters.AddWithValue("@a", Convert.ToInt32(ds2.Tables[0].Rows[0]["tedad"]) - Convert.ToInt32(dataGridView9.Rows[i].Cells[2].Value));
con.Open();
cmd4.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally { con.Close(); }
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
next1: ;
com1.Parameters.AddWithValue("@b", Convert.ToInt32(dataGridView9.Rows[i].Cells[1].Value));
com1.Parameters.AddWithValue("@c", Convert.ToInt32(dataGridView9.Rows[i].Cells[3].Value));
com1.Parameters.AddWithValue("@d", Convert.ToInt32(dataGridView9.Rows[i].Cells[2].Value));
com1.Parameters.AddWithValue("@e", Convert.ToInt32(lblcodefa4.Text));
con.Open();
com1.ExecuteNonQuery();
con.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally { con.Close(); }
}
MessageBox.Show(".فاکتور با موفقیت ویرایش شد");