class DBOperation
    {
        public const string aaa = "Data Source = .; Initial Catalog = Myschool;User id = sa;pwd = 110226";
        SqlConnection con = new SqlConnection(aaa);
        
        #region 按学号查询学生姓名
        public void queryname() {
            Console.WriteLine("请输入您要查询的学号:");
            string name =Console.ReadLine();
            try
            {
                String a = "select studentname from student where studentno ='name'";
                con.Open();
                SqlCommand com = new SqlCommand(a, con);
               SqlDataReader reader = com.ExecuteReader();               Console.WriteLine(reader);
            }
            catch (Exception)
            
            {
              
                Console.WriteLine("出现异常!");
            }
            finally {
                con.Close();
            }
        }
        #endregion为什么运行的时候总出来:System.Data.Sqlclient.SqlDataReader

解决方案 »

  1.   

    不仅如此,你的sqldatareader也用错了,先把你的sql语句改成
     String a = "select studentname from student where studentno ='"+name+"'";
    然后“Console.WriteLine(reader);”这句改成
    while (reader.Read())
                    {
                        Console.WriteLine(reader[0].ToString());
                    }