private void button1_Click(object sender, EventArgs e)
{
OleDbConnection dbconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=E:\a.mdb");
dbconn.Open();
foreach (ListViewItem lvi in lvLogs.Items) // 遍历整个listview将listview中的数据导出到数据库
{
//cmd.Parameters.Clear();
string strUserID = "", strCheckMode = "", strInoutMode = "", strDate = "";
int nGrade;
strUserID = lvi.SubItems[1].Text;
strCheckMode = lvi.SubItems[2].Text;
strInoutMode = lvi.SubItems[3].Text;
strDate = lvi.SubItems[4].Text;
nGrade = Convert.ToInt16(strCheckMode);
string cmdString = "insert into See([员工ID],[检验方式],[出入状态],[日期]) values(‘" + strUserID + "‘,‘" + nGrade + "‘,‘" + strInoutMode + "‘,‘" + strDate + "‘)";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = dbconn;
cmd.CommandText = cmdString;
cmd.ExecuteNonQuery();
//cmd.Dispose();
}
//关闭数据库的连接
dbconn.Close();
MessageBox.Show("导出已完成");
//dbconn.Dispose();
}