繁体中文
设为首页
加入收藏
当前位置:技术首页 >> 开发 >> .Net >> ADO.NET中的sql连接

ADO.NET中的sql连接

2008-04-01 22:30:39  作者:IT动力源  来源:IT动力源收集整理  浏览次数:0  文字大小:【】【】【
关键字:asp .net

using System.Data;            // Use ADO.NET namespace
using System.Data.SqlClient; 

 SqlConnection thisConnection = new SqlConnection(
            @"Data Source=GY; Initial Catalog=northwind;uid=sa;password=datadog"); //先建立连接
 thisConnection.Open();//打开连接
         SqlCommand thisCommand = thisConnection.CreateCommand();//直接指定conn的command
也可以这样        //  SqlCommand cmd = new SqlCommand();
       //  cmd.Connection = thisConnection;
cmmand的sql命令        
thisCommand.CommandText = "SELECT CustomerID, CompanyName from Customer";
         SqlDataReader thisReader = thisCommand.ExecuteReader();//sqldatareader不可以用new 必须直接与command关联
//用reader读出表
         while (thisReader.Read())
         {
            // Output ID and name columns
            Console.WriteLine("\t{0}\t{1}",
               thisReader["CustomerID"], thisReader["CompanyName"]);
         // Close reader 用完要关闭
         thisReader.Close();

         // Close connection
         thisConnection.Close ()

http://www.cnblogs.com/redcar/archive/2006/11/23/569859.html


点击收藏到

责任编辑:fwr

本文引用地址: http://tech.itzero.com/2008/0401/28859.html 请粘贴到你的QQ/MSN上推荐给你的好友

相关文章
 

最新文章

更多

· ADO.NET和LINQ中古怪的事...
· ADO.NET在开发中的部分使...
· ado.net执行oracle 存储过程
· ado.net 如何读取 excel
· Ado.net快马加鞭
· 数据库开发个人总结(ADO...
· ado.net数据库连接
· 使用ADO.NET2.0提升数据...
· 使用ADO.NET2.0提升数据...
· 使用ADO.NET2.0提升数据...

热点文章

更多

· ADO.NET性能改善方法集合
· 初谈ADO.NET中利用DataA...
· 通过ADO.NET实现事务处理
· 通过ADO.NET存取文件
· 下一代ADO.NET---ADO.NE...
· ADO.NET2.0跟ADO.NET3.0...
· ADO.NET 2.0:如何排除错...
· ADO.NET中的sql连接
· 使用ADO.NET2.0提升数据...
· 使用ADO.NET2.0提升数据...

其它推荐