namespace declaration question - 'Using system' causing error page

knightout

New member
Joined
Sep 24, 2022
Messages
1
Programming Experience
10+
Hi,

I'm trying to build a very simple site in C#/.Net as a front-end to a database but failing at the first hurdle and can't seem to find any help online.

I've done fairly extensive classic ASP/VB script many, many years ago, but this is a first attempt to do anything connecting to a db in c#.


What happens is, as soon as I try to declare the required namespaces, the page causes an error.

So, my .aspx page looks like this:


<%@ Page Language="c#" AutoEventWireup="true" CodeBehind="100char.aspx.cs" Debug="true" %>
<%
using System;
%>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html>
<head>
<title>test c# page</title>
</head>
<body>
<p>This page doesn't work.</p>
</body>
</html>




And the error is:


CS1003: Syntax error, '(' expected


If I take out the 'using System;' and put in some other standard code like 'string strWhatever="something"' the page works as expected.

I'm sure I'm missing something painfully obvious and basic, or maybe something that needs to be configured in IIS, but any help appreciated. Thank you.
 
You want to use <@Import > page directive.

 
Also worth reading in that documentation that I linked above, there are various namespaces that are already automatically imported, one of which is "System". So there is really no need for you to put in a line that says using System;.
 
Back
Top Bottom