您的位置:首页 > 数据库

菜鸟学习C#数据库实例练习使用SqlDataReader,SqlCommand SqlConnection

2009-07-02 10:37 951 查看
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string strCon="server=(local);database=northwind;uid=sa;pwd=123456";
string select="SELECT ContactName,CompanyName FROM Customers";
SqlConnection conn=new SqlConnection(strCon);
conn.Open();
SqlCommand cmd = new SqlCommand(select, conn);
SqlDataReader aReader = cmd.ExecuteReader();
while (aReader.Read())
Console.WriteLine("'{0}' from {1}", aReader.GetString(0), aReader.GetString(1));
aReader.Close();
conn.Close();

Console.ReadLine();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐