C#数据库与打印

C#打印

using System;

using System.Data.SqlClient;

namespace sqlserver2005

{

class showall

{

public static void show()

{

//创建数据库连接,三者选一,不需要设置ODBC数据源 SqlConnection aConnection = new SqlConnection(@"Data Source=(local);Initial Catalog=hotel;Integrated

Security=SSPI"); //hotel为数据源名

//SqlConnection aConnection = new

SqlConnection("server=JLU-LYLEGEND13\\SQLEXPRESS;Initial

Catalog=hotel;Integrated Security=SSPI"); //hotel为数据源名,JLU-LYLEGEND13为计算机名

//SqlConnection aConnection = new

SqlConnection("server=.;uid=admin;pwd=adminadmin;database=hotel"); //admin为账号,adminadmin为密码,database为数据库名

//创建command对象并保存sql查询语句

SqlCommand aCommand = new SqlCommand("select * from manager", aConnection);

try

{

aConnection.Open();

//创建datareader 对象来连接到表单

SqlDataReader aReader = aCommand.ExecuteReader(); Console.WriteLine("This is the returned data from emp_test table");

//循环遍历数据库

while (aReader.Read())

{

Console.WriteLine(aReader.GetString(0) + "\t" + aReader.GetString(1) + "\t" + aReader.GetString(2));

}

//关闭reader对象

aReader.Close();

你可能喜欢

  • by的用法
  • datagridview
  • 数据库课程设计实例
  • 加密解密
  • 字符串连接
  • 数据库加密
  • 文件加密

C#数据库与打印相关文档

最新文档

返回顶部