我一直遇到以下编译错误:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1519: Invalid token '=' in class, struct, or interface member declaration
Source Error:
Line 22:
Line 23: //Assign a Connection String
Line 24: conn.ConnectionString = ConfigurationManager.ConnectionStrings["sauceatronConnString"].ConnectionString;
Line 25:
Line 26: //Connection Open
Source Line: 24
只是想以一般编程和 ASP 和 C# 的新手作为开头。我之前使用相同的代码连接到数据库并且工作正常,但现在我遇到了那个我不太熟悉如何解决的错误。下面是我的 aspx 页面和我的 web.config 的代码。
<%@Page Language="C#" MasterPageFile="MasterPage/AtronsSiteMaster.master"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.Common"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Import Namespace="System.Configuration"%>
<%@ Import Namespace="System.Collections.Generic"%>
<asp:Content ContentPlaceHolderID="titleContentPlaceHolder" ID="titleContent" runat="server">Products</asp:Content>
<asp:Content ContentPlaceHolderID="headContentPlaceHolder" ID="headContent" runat="server"></asp:Content>
<script runat="server" language="C#">
String provider = ConfigurationManager.ConnectionStrings["sauceatronConnString"].ProviderName;
DbProviderFactory factory = DbProviderFactories.GetFactory(provider);
//Open a Connection
DbConnection conn = factory.CreateConnection();
//Assign a Connection String
conn.ConnectionString = ConfigurationManager.ConnectionStrings["sauceatronConnString"].ConnectionString;
//Connection Open
conn.Open();
//Initialize a Command
DbCommand comm = conn.CreateCommand();
//Tell the command which connection it will use
comm.Connection = conn;
//Give the command SQL to execute
comm.CommandText = "Select ProductName,ProductIssue,Writer,UnitPrice from Products order by ProductName, ProductIssue";
//Execute the command and get back the results via a reader
DbDataReader reader = comm.ExecuteReader();
//While we get results from the DB, add a row to the Table
while (reader.Read())
{
TableRow row = new TableRow();
TableCell cell;
cell = new TableCell();
cell.Text = reader["ProductName"].ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = reader["ProductIssue"].ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = reader["Writer"].ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = reader["UnitPrice"].ToString();
row.Cells.Add(cell);
}
//Free up the connection
conn.Close();
</script>
<asp:Content ContentPlaceHolderID="pageTitleContentPlaceHolder" ID="pageTitleContent" runat="server">Products</asp:Content>
<asp:Content ContentPlaceHolderID="mainContentPlaceHolder" ID="mainContent" runat="server">
<asp:Table ID="tblData" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell>Comic Book Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Issue</asp:TableHeaderCell>
<asp:TableHeaderCell>Writer Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Price</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</asp:Content>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
<connectionStrings>
<add name="databaseConnString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=~\Database\database.accdb;Persist Security Info=False;" providerName="System.Data.OleDb"/>
<add name="studentConnString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=~\Database\students.mdb;Persist Security Info=False;" providerName="System.Data.OleDb"/>
<add name="sauceatronConnString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=~\finals\Database\SauceAtronsVault.accdb;Persist Security Info=False;" providerName="System.Data.OleDb"/>
</connectionStrings>
</configuration>