最最基础的东西,长时间不写也会忘,一但要用的时候,回忆就是浪费时间!
选择“新建连接”以创建新的数据连接。
在“选择数据源”对话框中,选择“Microsoft SQL Server 数据库文件”。单击“确定”。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.sqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main_(string[] args)
{
String sql = "select * from emp"; //SQL查询语句
string connString = @"Data Source=./sqlEXPRESS;Initial Catalog=tt;User ID=sa;Password=tiger"; //sql数据库联接字符串
sqlConnection conn = new sqlConnection(connString); //数据库联接对象
sqlCommand comm = new sqlCommand(sql,conn); //命令对象
conn.open();
sqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection); //sqlDataReader对象,单步执行,速度快
while (reader.Read())
{
Console.WriteLine("id-----" + reader.GetInt32(0));
Console.WriteLine("name--------" + reader.GetString(2));
Console.WriteLine("age-------" + reader.GetInt32(1));
}
Console.ReadKey();
reader.Close();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。