欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#使用ODBC與OLEDB連接數(shù)據(jù)庫(kù)的方法示例

 更新時(shí)間:2017年05月12日 14:42:55   作者:aparche  
這篇文章主要介紹了C#使用ODBC與OLEDB連接數(shù)據(jù)庫(kù)的方法,結(jié)合實(shí)例形式分析了C#基于ODBC與OLEDB實(shí)現(xiàn)數(shù)據(jù)庫(kù)連接操作簡(jiǎn)單操作技巧,需要的朋友可以參考下

本文實(shí)例講述了C#使用ODBC與OLEDB連接數(shù)據(jù)庫(kù)的方法。分享給大家供大家參考,具體如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
using System.Data.OleDb;
namespace ODBCtest
{
  class Program
  {
    static void Main(string[] args)
    {
      //ODBC連接
      string conString = "DSN=tian"; //tian表示ODBC的用戶數(shù)據(jù)源名
      string sql = "select count(*) from stuinfo"; //stuinfo為用戶數(shù)據(jù)源綁定的數(shù)據(jù)庫(kù)中的一個(gè)表
      OdbcConnection con = new OdbcConnection(conString);
      con.Open();
      OdbcCommand com = new OdbcCommand(sql, con);
      int i = Convert.ToInt32(com.ExecuteScalar());
      Console.WriteLine(i);
      //OLEDB連接
      string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\tian.mdb"; //連接Access數(shù)據(jù)庫(kù)
      string sql = "select count(*) from stuinfo";
      OleDbConnection con = new OleDbConnection(conString);
      con.Open();
      OleDbCommand com = new OleDbCommand(sql, con);
      int i = Convert.ToInt32(com.ExecuteScalar());
      Console.WriteLine(i);
    }
  }
}

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#常見(jiàn)控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論