I save rows of datagridview in a table with this code:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
OleDbConnection conn;
OleDbCommand cmd;
string connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|" + "\\DB\\" + Class.Global.CurrentYear;
conn = new OleDbConnection(connectionstring);
cmd = conn.CreateCommand();
cmd = new OleDbCommand("INSERT INTO DocReportFixSalaryJoda (RowNumber,CMonth,Shahrestan,ComputerCode,ShomarehHesab, CName, FixSalary, BimehEjtemaeiBist, GhabelHazineh, BimehEjtemaeiHaft, MaliatTotal, TotalKosour,VighehPardakhti) VALUES (@RowNumber,@CMonth,@Shahrestan,@ComputerCode,@ShomarehHesab, @CName, @FixSalary, @BimehEjtemaeiBist,@GhabelHazineh, @BimehEjtemaeiHaft, @MaliatTotal, @TotalKosour,@VighehPardakhti);", conn);
cmd.Parameters.AddWithValue("@RowNumber", dataGridView1.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@CMonth", lblMonth.Text.Trim());
cmd.Parameters.AddWithValue("@Shahrestan", lblShahrestan.Text.Trim());
cmd.Parameters.AddWithValue("@ComputerCode", dataGridView1.Rows[i].Cells[1].Value);
cmd.Parameters.AddWithValue("@ShomarehHesab", dataGridView1.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@CName", dataGridView1.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@FixSalary", dataGridView1.Rows[i].Cells[4].Value);
cmd.Parameters.AddWithValue("@BimehEjtemaeiBist", dataGridView1.Rows[i].Cells[5].Value);
cmd.Parameters.AddWithValue("@GhabelHazineh", dataGridView1.Rows[i].Cells[6].Value);
cmd.Parameters.AddWithValue("@BimehEjtemaeiHaft", dataGridView1.Rows[i].Cells[7].Value);
cmd.Parameters.AddWithValue("@MaliatTotal", dataGridView1.Rows[i].Cells[8].Value);
cmd.Parameters.AddWithValue("@TotalKosour", dataGridView1.Rows[i].Cells[9].Value);
cmd.Parameters.AddWithValue("@VighehPardakhti", dataGridView1.Rows[i].Cells[10].Value);
try
{
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleResult);
}
catch
{
MessageBox.Show("ایرادی در عملیات وجود دارد");
}
finally
{
cmd.Dispose();
}
}
then I send this table to reportviewer.when i use break point to check code the row of datagrid has saved in table correctly but when i remove break point it not saved correctly.