当前位置:首页 > 网络编程 > 软件语言 > .NET > .Net中如何连接到ODBC数据源

.Net中如何连接到ODBC数据源

点击次数:64 次 发布日期:2008-11-06 08:13:14 作者:源代码网
源代码网推荐
广告载入中

源代码网整理以下1.下载ODBC.NET (FrameWork 2.0以上默认未安装)

源代码网整理以下下载地址:http://www.microsoft.com/downloads/details.aspx?familyid=6ccd8427-1017-4f33-a062-d165078e32b1

源代码网整理以下2.创建项目,添加Microsoft.Data.ODBC.dll 引用

源代码网整理以下3.cs代码如下:

源代码网整理以下using System.Data;
using Microsoft.Data.Odbc;
4.连接代码示例:

源代码网整理以下SqlServer:

源代码网整理以下OdbcConnection cn;
        OdbcCommand cmd;
        string MyString;

源代码网整理以下        MyString="Select * from Customers";

源代码网整理以下        cn= new OdbcConnection("Driver={SQL Server};Server=mySQLServer;UID=sa;
                               PWD=myPassword;Database=Northwind;");

源代码网整理以下        cmd=new OdbcCommand(MyString,cn);
        cn.Open();

源代码网整理以下        MessageBox.Show("Connected");

源代码网整理以下        cn.Close();
 

源代码网整理以下OLEDB JET:

源代码网整理以下OdbcConnection cn;
        OdbcCommand cmd;
        string MyString;

源代码网整理以下        MyString="Select * from Titles";

软件开发网 www.mscto.com

源代码网整理以下        cn= new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};
            DBQ=D:Program FilesMicrosoft OfficeOffice10SamplesNorthwind.mdb;UID=;PWD=;");
             
        cmd=new OdbcCommand(MyString,cn);
        cn.Open();
        MessageBox.Show("Connected");

源代码网整理以下        cn.Close();
Oracle:

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下OdbcConnection cn;
       OdbcCommand cmd;
       string MyString;

源代码网整理以下       MyString="Select * from Customers";

源代码网整理以下       cn= new OdbcConnection("Driver={Microsoft ODBC for oracle};Server=myOracleServer;
                               UID=demo;PWD=demo;");

源代码网整理以下       cmd=new OdbcCommand(MyString,cn);
       cn.Open();

源代码网整理以下       MessageBox.Show("Connected");

源代码网整理以下       cn.Close();

源代码网整理以下
DSN:

源代码网整理以下 

源代码网整理以下OdbcConnection cn;
       OdbcCommand cmd;
       string MyString;

源代码网整理以下       MyString="Select * from Customers";

源代码网整理以下       cn= new OdbcConnection("dsn=myDSN;UID=myUid;PWD=myPwd;");

源代码网整理以下       cmd=new OdbcCommand(MyString,cn);

源代码网整理以下       cn.Open();
       MessageBox.Show("Connected");

源代码网整理以下       cn.Close();


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华