错误枚举对SqlDataReader没有产生任何结果

时间:2019-09-23 06:09:55

标签: c# sql compiler-errors ado.net sqldatareader

  

错误Enumeration对于SqlDataReader没有结果

     

系统信息:::

     

到Microsoft Visual Studio Enterprise 2015版本14.0.25123.0 D14REL   Microsoft .NET Framework版本4.7.03062

     

安装的版本:Enterprise SQL Server数据工具14.0.50616.0   Microsoft SQL Server数据工具

string connString =
        "Data Source=.;" +
        "Initial Catalog=library;" +
        "User id=book;" +
        "Password=sa;";
       // conn.Open();
        using (SqlConnection c = new SqlConnection(connString))
        {
            sql = @"SELECT * FROM kala";
            // conn.Close();

            SqlCommand cn = new SqlCommand(sql, c);

             c.Open();

            SqlDataReader dr = cn.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    //empID = dr.GetInt32(0);
                    //empCode = dr.GetString(1);
                    //empFirstName = dr.GetString(2);
                    //empLastName = dr.GetString(3);
                    //locationCode = dr.GetString(4);
                    //locationDescr = dr.GetString(5);

                    //display retrieved record
                    //Console.WriteLine("{0},{1},{2},{3},{4},{5}", empID.ToString(), empCode, empFirstName, empLastName, locationCode, locationDescr);
                }
            }
        }

0 个答案:

没有答案
相关问题