System.Data.SQL->System.Data.SqlClient正式版没有SQL这个命名空间,那是Beta版的

解决方案 »

  1.   

    能不能帮我看一下我下面的程序错在哪?
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %><html>
    <script language="C#"  Debug="true" runat="server">
       
        protected void Page_Load(Object Src,EventArgs E)
        {
          SqlConnection mySQLConnection= new SqlConnection("server=localhost;uid=ms;pwd=ms;database=aspbook");
          SqlCommand mySQLCommand= new SqlCommand("select * from student",mySQLConnection);
        try
        {
          mySQLConnection.Open();
          SqlDataReader MyReader=mySQLCommand.ExecuteReader(CommandBehavior.CloseConnection);
          Response.Write("<Table border=1>");
          Response.Write("<TR>");
          Response.Write("<TD>");
          Response.Write("<B>学号 </B>");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write("<B>姓名 </B>");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write("<B>年纪 </B>");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write("<B>班级 </B>");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write("<B>备注 </B>");
          Response.Write("</TD>");
          Response.Write("</TR>");
          
          while (MyReader.Read())
          {
          Response.Write("<TR>");
          Response.Write("<TD>");
          Response.Write(MyReader["no"].ToString()+"&nbsp;");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write(MyReader["name"].ToString()+"&nbsp;");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write(MyReader["age"].ToString()+"&nbsp;");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write(MyReader["class"].ToString()+"&nbsp;");
          Response.Write("</TD>");
          Response.Write("<TD>");
          Response.Write(MyReader["mem"].ToString()+"&nbsp;");
          Response.Write("</TD>");
          Response.Write("</TR>");
          }
          Response.Write("</Table>");
         }
         catch(Exception e)
         {
            Response.Write(e.ToString());
         }
         finally
         {
          ' MyReader.Close();
           mySQLConnection.Close();
          }
         }
         </script>    
     </html>
      

  2.   

    说MyReader不在名字空间下,没有用using
      

  3.   

    是不是没添加引用:
      方法:资源管理器中选“引用”,右鍵“添加引用”,选.net页,选“System.Data.dll”,
    试试。
      

  4.   

    finally
         {
          ' MyReader.Close();
           mySQLConnection.Close();
          }
    改成:
    finally
         {
          // MyReader.Close();
           mySQLConnection.Close();
          }C#注释用//,而不是'
      

  5.   

    不是这个问题了,
    上面的例子我是用文本编辑器写的,不好引用等操作
    我现在是在visual C#.net环境下做,但又有一个问题是:在这个环境下连接数据库可以
    而且,可以预览表中的数据,但是运行时,即在IE中打开却说用户名不能访问