zoukankan      html  css  js  c++  java
  • 用Visual C#向access添加数据

    (1)创建并打开一个OleDbConnection对象。

    (2)创建一个插入一条记录的SQL语句。

    (3)创建一个OleDbCommand对象。

    (4)通过此OleDbCommand对象完成对插入一条记录到数据库的操作。

      以下是在程序中实现的具体语句:

    string strConn = " Provider = Microsoft.Jet.OLEDB.4.0  Data Source = sample.mdb "  

    OleDbConnectionmyConn = new OleDbConnection ( strConn )  

    myConn.Open ( )  

    string strInsert = " INSERT INTO books ( bookid , booktitle , bookauthor , bookprice , bookstock ) 

    VALUES ( "  

    strInsert += t_bookid.Text + ", '"  

    strInsert += t_booktitle.Text + "', '"  

    strInsert += t_bookauthor.Text + "', "  

    strInsert += t_bookprice.Text + ", "  

    strInsert += t_bookstock.Text + ")"  

    OleDbCommandinst = new OleDbCommand ( strInsert , myConn )  

    inst.ExecuteNonQuery ( )  

    myConn.Close ( )  

  • 相关阅读:
    WCF上传下载文件
    WCF使用相关
    .net WCF WF4.5 状态机、书签与持久化
    .net WCF WF4.5
    CSS小东西
    asp.net mvc导出execl_转载
    winform自定义控件开发
    html问题汇总
    工作中的小东西
    jQuery事件
  • 原文地址:https://www.cnblogs.com/lizeyang/p/5254161.html
Copyright © 2011-2022 走看看