Bạn xem cái ví dụ bên dưới là mình lưu toàn bô gridview vào database. Bạn có thể thêm checkbox rồi ghi.
Code:
private void btnpayment_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Are you sure to close Check Out ?" + txtmainid.Text, "(ESP Stock Management System) Confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
if (dgvhienthi.Rows.Count != 0)
{
for (int i = 0; i < dgvhienthi.RowCount; i++)
{
using (DALHelper dal = new DALHelper())
{
try
{
dal.OpenDB();
DA = new OleDbDataAdapter("insert into t_export(exportid, idcard, productid, Buyer, stylename, season, typedetail, sex, size, qty, price, amount, kieu, createby, createdate) values('" + txtmainid.Text + "','" + txtidcard.Text + "','" + dgvhienthi.Rows[i].Cells[0].Value + "','" + dgvhienthi.Rows[i].Cells[1].Value + "','" + dgvhienthi.Rows[i].Cells[2].Value + "','" + dgvhienthi.Rows[i].Cells[3].Value + "','" + dgvhienthi.Rows[i].Cells[4].Value + "', '" + dgvhienthi.Rows[i].Cells[5].Value + "', '" + dgvhienthi.Rows[i].Cells[6].Value + "', '" + dgvhienthi.Rows[i].Cells[7].Value + "', '" + dgvhienthi.Rows[i].Cells[8].Value + "', '" + dgvhienthi.Rows[i].Cells[9].Value + "', 'Sell', '" + txtcreatedby.Text + "', '" + txtcreateday.Text + "' )", dal.dbCon);
DataSet DS4 = new DataSet();
DA.Fill(DS4, "t_export");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
finally
{
dal.CloseDB();
}
}
}