user2962142
user2962142

Reputation: 2066

How to use the "Using" statement in ASP.net razor webpages?

So I need to add a "using" statement which is :

using System.Data.SqlClient 

in my webpage so i dont have to call whats inside the SqlClient with the whole statement

 System.Data.SqlClient.SqlConnection con = new ..

How to do that ?

note that i added the reference System.Data to my webconfig file.

Upvotes: 23

Views: 19850

Answers (1)

CodeNotFound
CodeNotFound

Reputation: 23220

At the top of your Razor View just add

@using System.Data.SqlClient 

Notice the @ char before the using statement.

Or inside a block like below:

@{
    using System.Data.SqlClient;
}

Side note: it's a little bit weird to use a SqlConnection into a Razor View.

Upvotes: 40

Related Questions