1

I'm just starting out learning C# this may be really simple but in VB i have these namespaces

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>

How do I go about using those namespaces in C#?

I tried

namespace System.Data

and

using System.Data

but they didn't work

1
  • 2
    You need to end the using statement with a ; Commented Nov 4, 2010 at 18:03

4 Answers 4

9

Are you trying to import namespaces into an Asp.net page? If so the code you listed with a case change will work fine.

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

If you're trying to import them into an actual .cs file then you need the "using" directive

using System.Data;
using System.Globalization;
Sign up to request clarification or add additional context in comments.

6 Comments

I'm importing them into a aspx page - Case change did the trick - Thanks
Should I be using .cs files instead of .aspx?
@Jamie for the actual HTML / ASP.Net content ASPX is the right place. I just mentioned the .cs file because I couldn't tell from the question which file you were having a problem with so I put the solution for both.
@Jamie Taylor: Yes. Yes you should. Although you are permitted to do so by the ASP.NET framework (mostly in an effort to bring in classic ASP programmers) you should, for maintainability's sake, have no actually executable code in your .aspx file. There are always niche reasons to break that rule, but as a general rule, it's an big one.
@Jamie Taylor: Your executable code should be in the code-behind for whatever control you're writing the code, be it a page (.aspx), user control (.ascx) or a master page (.master). The code should respond to events fired in the page/control lifecycle, modifying data in controls defined in the markup file as necessary before being rendered.
|
0
using System.Data;

Comments

0
using System.Data;
using System.Globalization;
using System.Data.SqlClient;

public class MyClass {}

Comments

0

These:

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>

are ASP.NET page directives. They'll be the same whether your code-behind files are C# or VB.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.