<%@ Import Namespace="System.Data.Sql" %>换成
<%@ Import Namespace="System.Data.Sqlclient" %>

解决方案 »

  1.   

    我试了还是不行,出现如下错误:编译错误 
    说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0246: 找不到类型或命名空间名称“SQLConnection”(是否缺少 using 指令或程序集引用?)源错误:
    行 5:    string mySelectQuery = "SELECT * from Company";
    行 6:    string myConnString="server=localhost;uid=sa;pwd=;database=search";
    行 7:    SQLConnection myConnection = new SQLConnection(myConnString);
    行 8:    SQLCommand myCommand = new SQLCommand(mySelectQuery,myConnection);
    行 9:    myConnection.Open();
      

  2.   

    <%
      string str_Query = "SELECT * from Company";
      string str_Conn="server=localhost;uid=sa;pwd=;database=search";
      SQLConnection myConnection = new SQLConnection(str_Conn);
      SQLCommand myCommand = new SQLCommand(str_Query,str_Conn);
      myConnection.Open();
    %>
    你怎么这样写呢?

    <script language="c#" runat=server>
    string str_Query = "SELECT * from Company";
      string str_Conn="server=localhost;uid=sa;pwd=;database=search";
      SQLConnection myConnection = new SQLConnection(str_Conn);
      SQLCommand myCommand = new SQLCommand(str_Query,str_Conn);
      myConnection.Open();
    </script>
      

  3.   

    注意 ,应该是:SqlConnection/SqlCommand不是:SQLConnection/SQLCommand前面只有“S”是大写,C#的大小写是不一样的。
      

  4.   

    我现在具体也记不清,在哪个名字空间了,你可以在msdn.net中搜索有疑问的对象,就可以知道答案了。