Compilation error in C#/ASP.NET app - CS1519: Invalid token 'using' in class, struct, or interface m

E

Erik H.

I have an ASPX page in which I am trying to bind a datagrid to a dataset
pulled from Microsoft Access DB using code inline method. For some reason,
the compiler is having a problem with 'using'. Any help here would be much
appreciated. Thanks!

Getting the following error:
CS1519: Invalid token 'using' in class, struct, or interface member
declaration

My Code:
<%@ Page Language="C#" %>
<script runat="server">

using System.Data;
using System.Data.oledb;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


private void Form_Load(object sender, System.EventArgs e)
{

// create a connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Dev\ATTRIBUTES_VH\ATTRIBUTES_VH.mdb";
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = connString;// create a data adapter
OleDbDataAdapter da = new OleDbDataAdapter("Select * from mytable",
myConnection);

// create a new dataset
DataSet ds = new DataSet();

// fill dataset
da.Fill(ds, "RateCenters");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds.DefaultViewManager;
DataGrid1.databind()

myConnection.close()
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</form>
</body>
</html>
 
D

David Browne

Erik H. said:
I have an ASPX page in which I am trying to bind a datagrid to a dataset
pulled from Microsoft Access DB using code inline method. For some reason,
the compiler is having a problem with 'using'. Any help here would be much
appreciated. Thanks!

Getting the following error:
CS1519: Invalid token 'using' in class, struct, or interface member
declaration

My Code:
<%@ Page Language="C#" %>
<script runat="server">

using System.Data;
using System.Data.oledb;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

Remember you're not writing C#, you're writing input for the ASP.NET
precompiler which will become C#.
The precompiler replaces tags like:

<%@ import namespace="System.Data.oledb" %>

with C# using statements.

David
 
E

Erik H.

So when I'm using the code inline method, I need to use <%@ import
namspace="<namespace>"%> instead?

Sorry if this is a stupid question, I just want to be clear.

Thanks David!
 
D

David Browne

Erik H. said:
So when I'm using the code inline method, I need to use <%@ import
namspace="<namespace>"%> instead?

Sorry if this is a stupid question, I just want to be clear.

Yes. And poke around in the generated C# source files, they are your window
into what the ASP.NET precomiler is doing.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top