Add data to the Access database using ADO

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
Add data to the database using ADO

tools Used : Visual C# .NET

This program shows how to insert data in an Access database using ADO and SQL query. I have an Access 2000 database in project/bin/debug 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.

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:/n{0}", e.Message);  
                  }  
                  finally  
                  {  
                        myConn.Close();  
                  }  
   
   
   
            }
      }  
}  
   






11AID0422054029.jpg
seover="window.status='正文--Add data to the Access database using ADO';return true">
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

Delphi WinSoft Component

2008年09月02日 2.61MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭