Add data to the Access database using ADO

2016-02-19 13:29 4 1 收藏

清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐Add data to the Access database using ADO,无聊中的都看过来。

【 tulaoshi.com - 编程语言 】

Add data to the database using ADO

Tools Used : Visual C# .NET

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

This program shows how to insert data in an access database using ADO and SQL query. I have an Access 2000 database in projectindebug directory. My database name is mcTest.MDB. You can create your own database and copy in your project's debug directory. I am not attaching database with this code because of size problem.

I have a table 'Developer' in this database which has four columns. I am inserting values into two columns Name and Address in this code.

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

using System;
using System.Data;  
using System.Data.OleDb;  
namespace ADONETWriteQuery 
{
      /// summary
      /// Summary description for Class1.
      /// /summary
      class Class1
      { 
            static void Main(string[] args) 
            { 
                  string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:mcTest.MDB"; 
                  string strSQL = "INSERT INTO Developer(Name, Address ) VALUES(
'NewName', 'NewAddress')" ; 
                  
                  // create Objects of ADOConnection and ADOCommand  
                  OleDbConnection myConn = new OleDbConnection(strDSN); 
                  OleDbCommand myCmd = new OleDbCommand( strSQL, myConn ); 
                  try 
                  { 
                        myConn.Open(); 
                        myCmd.ExecuteNonQuery(); 
                  } 
                  catch (Exception e) 
                  { 
                        Console.WriteLine("Oooops. I did it again:{0}", e.Message); 
                  } 
                  finally 
                  { 
                        myConn.Close(); 
                  }  
   
            }
      } 

来源:http://www.tulaoshi.com/n/20160219/1604473.html

延伸阅读
你知道ADO控件和DATA控件有冲突吗?试一试下面的例子: DimdbAsDatabase DimrsAsRecordset Setdb=OpenDatabase("d:stockyline.mdb") Setrs=db.OpenRecordset("selectcount(*)astotalcountfromylinewhere条件")*** MsgBox(rs(0)) rs.Close db.Close Setrs=Nothing Setdb=Nothing ‘注明,这个例子...
标签: Web开发
       今天有位朋友问我如何在Data Access Application Block中得到存储的过程的返回值,我才发现自己以前写的文章中确实没提到这方面的问题,现在来补充一下,具体的解决方法如下: 1、首先建立一个具有返回值的存储过程,作为示例,我就简单的建一个存储过程,如下: create proc test ( &n...
标签: Web开发
Most users will only want to use the innerText/innerHTML and outerText/outerHTML properties and methods discussed previously. However, there is some more advanced text manipulation that can ...
ado技术目前已经成为连接数据库的主流技术,下面我来介绍如何使用ado来动态创建access数据库。为了使用ado,必须引入微软的两个动态连接库msadox.dll和msado15.dll:     #pragma warning (disable: 4146)     #import "c:Program FilesCommon Filessystemadomsadox.dll"     #import "c:Progr...
标签: ASP
  HOWTO: Compacting Microsoft Access Database via ADO -------------------------------------------------------------------------------- The information in this article applies to: ActiveX Data Objects (ADO), versions 2.1, 2.5, 2.6 Microsoft OLE DB Provider for Jet, version 4.0 --------------------------------...

经验教程

992

收藏

64
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部