PDA

View Full Version : عدم ذخیره اطلاعات دیتاگریدویو در بانک



sini65
دوشنبه 08 آبان 1402, 20:10 عصر
من اطلاعات را به وسیله اکسل وارد دیتاگریدویو میکنم وقتی اطلاعات را در بانک ذخیره میکنم فقط اطلاعات سطر اول دیتاگریدویو ذخیره میشه و بقیه سطرها ذخیره نمیشه
چیکارکنم؟
155034

پرستو پارسایی
چهارشنبه 10 آبان 1402, 09:00 صبح
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
OleDbConnection con = new OleDbConnection();
Properties.Settings set128 = new ph1402.Properties.Settings();
con.ConnectionString = set128.sobhaniConnectionString;
OleDbCommand scom = new OleDbCommand();
scom.CommandText = "INSERT INTO khad (mokh, fsh, zam, koda, emil, site, modd, tov, adsh, ksh, tsh, hsh, ax) VALUES (@f0, @f, @ff, @sh, @ma, @mal, @as, @ho, @ax, @ax1, @ax2, @ax3)";
scom.Connection = con;
scom.Parameters.AddWithValue("@f0", dataGridView1.Rows[i].Cells[0].Value);
scom.Parameters.AddWithValue("@f", dataGridView1.Rows[i].Cells[1].Value);
scom.Parameters.AddWithValue("@ff", dataGridView1.Rows[i].Cells[2].Value);
scom.Parameters.AddWithValue("@sh", dataGridView1.Rows[i].Cells[3].Value);
scom.Parameters.AddWithValue("@ma", dataGridView1.Rows[i].Cells[4].Value);
scom.Parameters.AddWithValue("@mal", dataGridView1.Rows[i].Cells[5].Value);
scom.Parameters.AddWithValue("@as", dataGridView1.Rows[i].Cells[6].Value);
scom.Parameters.AddWithValue("@ho", dataGridView1.Rows[i].Cells[7].Value);
scom.Parameters.AddWithValue("@ax", dataGridView1.Rows[i].Cells[8].Value);
scom.Parameters.AddWithValue("@ax1", dataGridView1.Rows[i].Cells[9].Value);
scom.Parameters.AddWithValue("@ax2", dataGridView1.Rows[i].Cells[10].Value);
scom.Parameters.AddWithValue("@ax3", dataGridView1.Rows[i].Cells[11].Value);


OleDbDataAdapter sda = new OleDbDataAdapter();
sda.InsertCommand = scom;
con.Open();
sda.InsertCommand.ExecuteNonQuery();
con.Close();
}


MessageBox.Show("پیام مورد نظر");