All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
ADO.NET中的sql连接_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/10 6:23:35 Browse times: 353 Comment times: 0

ADO.NET中的sql连接_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

ADO.NET中的sql连接_[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





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.