用C#读SQL SERVER到控制台的简单示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//string sqlconn = "server=(local);database=keede1228;user id=sa;password=123;";
//windows身份验证
string sqlconn = "server=(local);database=keede1228;integrated security=SSPI;";
string select = "select * from dbo.lmShop_City";
SqlConnection conn = new SqlConnection(sqlconn);
Console.WriteLine("33");
conn.Open();
Console.WriteLine("11");
SqlCommand cmd = new SqlCommand(select, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("cityid:{0} city:{1} area:{2}", reader[0], reader[1], reader[2]);
}
conn.Close();
Console.WriteLine("22");
Console.ReadKey();
}
}
}
有一点疑问:最后输出到控制台的时候,如果不加"cityid:{0} city:{1} area:{2}"就会报错,不知道是为什么,好像是类型转换的事,有明白的帮我解答一下,谢谢。
相关文档:
一般的远程访问的写成这样:
Data Source=IP;Initial Catalog=数据库名;UserID=用户名;Password=密码
本地访问的写成这样:
Data Source=(local);Initial Catalog=数据库名;UserID=用户名;Password=密码
如果是本地的,通过windows组件验证的(也就是没有用户名,密码的)写成这样:
Data Source=(local);Initial Cata ......
http://topic.csdn.net/u/20100113/17/b52a1ef4-54a8-4333-8119-a161869c1eef.html
---------------------------------
-- Author: liangCK 小梁
-- Title : 查每个分组前N条记录
-- Date : 2008-11-13 17:19:23
---------------------------------
--> 生成测试数据: #T
IF OBJECT_ID(' ......
---1、添加数据文件
use master
go
--Fam200901
alter database RedfDB
add filegroup FGAM200901
go
alter database RedfDB
add file(name='FGAM200901',filename='D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\Fam200901.mdf',
size=20,maxsize=40,filegrowth=10% ......
ORA-07445 与 PL/SQL Developer 案例一则
作者:eygle |English Version 【转载时请以超链接形式标明文章出处和作者信息及本声明】
链接:http://www.eygle.com/archives/2009/02/ora_07445_plsql_developer.html
--------------------------------------------------------------------------------
前几天,又有一个 ......