using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Threading.Tasks; |
using System.Data; |
//对SQL server数据库的访问 |
using System.Data.SqlClient; |
namespace ConsoleApplication1 |
{ |
class Program |
{ |
static void Main(string[] args) |
{ |
SqlConnection con = new SqlConnection(); |
con.ConnectionString = "Data Source=.;database=学生成绩管理系统;uid=sa;pwd=252525" ; |
con. Open (); |
if (con.State == ConnectionState. Open ) |
{ |
SqlCommand com=new SqlCommand() ; |
com.CommandType=CommandType.Text; |
com.CommandText = "select 学号,姓名,性别,出生日期 from 学生信息" ; //设置Transact-SQL语句或者储存过程 |
com. Connection = con; |
SqlDataReader dr = com.ExecuteReader(); //将数据保存在dr中 |
while (dr. Read ()) |
{ |
Console.WriteLine( "学号:{0}姓名:{1}性别:{2}出生日期:{3}" , dr.GetString(0), dr.GetString(1), dr.GetString(2),dr.GetDateTime (3)); |
|
} |
Console. Read (); |
} |
con. Close (); |
} |
} |
} |