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 学生信息" ; |
com. Connection = con; |
SqlDataReader dr = com.ExecuteReader(); |
dr. Read (); |
Console.WriteLine( "学号:{0}姓名:{1}" ,dr.GetString (0),dr.GetString (1)); |
Console. Read (); |
} |
con. Close (); |
} |
} |
} |