using System; using System.Data.SqlClient; namespace AdoTest { class ado { static void Main(string[] args) { String connectionString = @"server=标哥-PC\SQLEXPRESS2005;database=student;uid=sa;pwd=tianshi520"; SqlConnection sqlConn = new SqlConnection(connectionString);//创建Connection对象 SqlCommand sqlCmd = sqlConn.CreateCommand();//创建Command对象 string commandString = "select sno, sname from s";//SQL命令语句 sqlCmd.CommandText = commandString;// sqlConn.Open();//打开数据库 SqlDataReader sqlDR = sqlCmd.ExecuteReader();//获取读取对象 sqlDR.Read();//读取一行记录 Console.WriteLine("Sno: " + sqlDR["Sno"]);//读取学号 Console.WriteLine("Sname: " + sqlDR["Sname"]);//读取姓名 sqlDR.Close(); //关闭记录集 sqlConn.Close(); //断开数据库连接 } } }
这个是C#控制台程序!
时间: 2024-10-30 13:58:34