码迷,mamicode.com
首页 > 数据库 > 详细

.NET通过ODBC 连接 SQL SERVER

时间:2014-10-13 19:15:26      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   div   on   

通过ODBC连接到SQL SERVER的两种方法:

一、通过加载SQL SERVER驱动方式;

二、通过配置DSN名称;

 string constr = "driver={sql server};database=" + databaseNAME+ ";server=" + 服务器地址 + ";"//SQL SERVER驱动
  constr += "UID=invuser;PWD=1;"

OdbcCommand cmd_s = new OdbcCommand(sSQL, conn_odbc); 
                        OdbcDataReader reader_s = cmd_s.ExecuteReader();//执行查询
                        int iCZ = 0;
                        while (reader_s.Read())
                        {
                            JLBH_OUT.Add(data.iJLBH);
                            iCZ=1;
                        }
                        reader_s.Close();

sSQL = " insert into dbo(操作员名称,导出日期) values ";
string stmp = "(";
stmp += "" + sDJRMC + "‘,getdate()";
stmp += ")";
sSQL += stmp;
OdbcCommand cmd_in = new OdbcCommand(sSQL, conn_odbc);
int iInsert = cmd_in.ExecuteNonQuery(); //执行插入
conn_odbc.Close();

 

OdbcConnection cn;
       OdbcCommand cmd;
       string MyString;
       MyString="Select * from dbo";
       cn= new OdbcConnection("dsn=myDSN;UID=invuser;PWD=1;");//通过DSN
       cmd=new OdbcCommand(MyString,cn);
       cn.Open();
       MessageBox.Show("Connected");
       cn.Close();

 

.NET通过ODBC 连接 SQL SERVER

标签:style   blog   color   io   os   ar   sp   div   on   

原文地址:http://www.cnblogs.com/yuanzhongkui/p/4022557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!