使用System.Data.Odbc编译错误;

时间:2011-08-01 14:29:53

标签: .net asp.net

我只是第一次尝试使用aspx而且我得到了一个     CS1003:语法错误,'('预期 第3行出错。

这是我的代码:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<%
    using System.Data.Odbc;
    // Connection
    string connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=db;User=user;password=pass";
    OdbcConnection conn = new OdbcConnection(connectionString);
    conn.open();
%>

我不确定“使用”行有什么问题。任何帮助将非常感激。

1 个答案:

答案 0 :(得分:3)

<% ... %>块的内容是语句,它们放在Execute方法内。
您不能在方法中放置using指令。

相反,您需要使用ASP.Net <%@ Import %> directive

<%@ Import Namespace="System.Data.Odbc" %>