با سلام
دوستان من یک گرید دارم که بایند نیست و کاربر اطلاعات را سطر به سطر در آن وارد می کند و با زدن دکمه ای اطلاعات از گرید به بانک به صورت سطر به سطر وارد می شوند.مشکل اینجاست آخرین سلولی که کاربر داده وارد می کنه در بانک ذخیره نمی شه (فقط آخرین سلول وارد نمی شه)حالا اون سلول می تونه هر کدوم ار سلولهای گرید باشه بسته به اینه که آخرین سلول کاربر واسه ورود داده هست یا نه.
این مشکل دیوانم کرده بچه ها خواهشن کمکم کنید پروژرو باید تا 4 روز دیگه تحویل بدم.اینم کدی که نوشتم:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
//MessageBox.Show(dataGridView1.Rows.Count.ToString( ));
string s = @"Insert into EmissionDoc (Id,NumReceipt,AccCode,Center1,Center2,Center3,Doc Account,ArzKind,Amount,Debtor,Creditor,NumPey
,Datepey,NumOrder)values
(@Id,@NumReceipt,@AccCode,@Center1,@Center2,@Cente r3,@DocAccount,@ArzKind,@Amount,@Debtor,@Creditor, @NumPey,
@Datepey,@NumOrder)";
SqlCommand Cmd = new SqlCommand(s, connect);
//SqlDataAdapter d = new SqlDataAdapter(s1, connect);
//DataTable t=new DataTable();
Cmd.Parameters.AddWithValue("Id",Convert.ToString( dataGridView1.Rows[i].Cells[0].Value));
Cmd.Parameters.AddWithValue("NumReceipt", textBox1.Text);
Cmd.Parameters.AddWithValue("AccCode",Convert.ToSt ring(dataGridView1.Rows[i].Cells[1].Value));
Cmd.Parameters.AddWithValue("Center1",Convert.ToSt ring(dataGridView1.Rows[i].Cells[2].Value));
Cmd.Parameters.AddWithValue("Center2",Convert.ToSt ring(dataGridView1.Rows[i].Cells[3].Value));
Cmd.Parameters.AddWithValue("Center3",Convert.ToSt ring(dataGridView1.Rows[i].Cells[4].Value));
Cmd.Parameters.AddWithValue("DocAccount",Convert.T oString(dataGridView1.Rows[i].Cells[5].Value));
Cmd.Parameters.AddWithValue("ArzKind",Convert.ToSt ring(dataGridView1.Rows[i].Cells[6].Value));
Cmd.Parameters.AddWithValue("Amount",Convert.ToStr ing(dataGridView1.Rows[i].Cells[7].Value));
Cmd.Parameters.AddWithValue("Debtor",Convert.ToInt 32(dataGridView1.Rows[i].Cells[8].Value.ToString().Replace(",","")));
Cmd.Parameters.AddWithValue("Creditor", Convert.ToInt32(dataGridView1.Rows[i].Cells[9].Value.ToString().Replace(",", "")));
Cmd.Parameters.AddWithValue("NumPey",Convert.ToStr ing(dataGridView1.Rows[i].Cells[10].Value));
Cmd.Parameters.AddWithValue("Datepey",Convert.ToSt ring(dataGridView1.Rows[i].Cells[11].Value));
Cmd.Parameters.AddWithValue("NumOrder", Convert.ToString(dataGridView1.Rows[i].Cells[12].Value));
// Cmd.Parameters.AddWithValue("NumOrder", dataGridView1.Rows[i].Cells[12].Value.ToString());
// Cmd.Parameters.AddWithValue("KolAccount", textBox3.Text);
// Cmd.Parameters.AddWithValue("MoeinAccount", textBox4.Text);
// Cmd.Parameters.AddWithValue("TafziliAccount", textBox5.Text);
// Cmd.Parameters.AddWithValue("Center1Account", label18.Text);
// Cmd.Parameters.AddWithValue("Center2Account", label19.Text);
// Cmd.Parameters.AddWithValue("Center3Account", label20.Text);
// Cmd.Parameters.AddWithValue("SumDebtor", label20.Text);
// Cmd.Parameters.AddWithValue("SumCreditor", label19.Text);
Cmd.ExecuteNonQuery();
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString());
}
finally
{
connect.Close();
}