zoukankan      html  css  js  c++  java
  • C# 实现将listview中已经显示的数据导出到Access 数据库

    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();

    }

  • 相关阅读:
    Console
    在IOS10系统中无法定位问题
    c# js 时间
    ConcurrentDictionary,ConcurrentStack,ConcurrentQueue
    转 控件拖动 未验证
    消息处理模拟点击
    C ProcessAsUser
    SessionChange
    installer
    mysql主从同步配置
  • 原文地址:https://www.cnblogs.com/tianjiaxiaobaicai/p/4334988.html
Copyright © 2011-2022 走看看