Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:34+00:00 2026-05-23T13:44:34+00:00

I have a C#/ASP.net project has included a database that I have developed that

  • 0

I have a C#/ASP.net project has included a database that I have developed that includes a nice and convenient View that would be handy to use.

I have the SQL connection setup to a SQL Server 2008 DB I created. It seems as though it is connecting fine, but I don’t understand how to actually use the View that I created without hard coding the query into the program (been told this is bad sometimes?).

This is my connection I setup:

    SqlConnection conn = null;
    conn = new SqlConnection("Data Source=raven\\sqlexpress;Initial Catalog=ucs;Integrated Security=True;Pooling=False");
    conn.Open(); 
    SqlCommand command = new SqlCommand(query, conn);

Basically, I need some code to query using this View. I can see the View and look at the results that would be obtained, but not access it in the program!
The view is named “UserView”. Help is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:44:35+00:00Added an answer on May 23, 2026 at 1:44 pm

    You could use something like the following. But it’s usually considered evil to put hardcoded SQL commands into .Net code. It’s much better and safer to use stored procedures instead.

    This should get you started. You can modify it to use stored procedures by

    1. changing the command.CommandType to indicate it’s a stored proc call
    2. And adding the proper parameters to the command that your SP needs.
    3. Change command.CommandText to the name of your SP, thus
      eliminating the hardcoded SQL.

    sample code below:

    using (SqlConnection connection = new SqlConnection("Data Source=raven\\sqlexpress;Initial Catalog=ucs;Integrated Security=True;Pooling=False"))
    {
        using (SqlCommand command = connection.CreateCommand())
        {
            command.CommandText = "SELECT * from your_view WHERE your_where_clause";
    
            connection.Open();
            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    // process result
                    reader.GetInt32(0); // get first column from view, assume it's a 32-bit int
                    reader.GetString(1); // get second column from view, assume it's a string
                    // etc.
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a visual studio 2008 solution that includes an asp.net-hosted remoting project in
I have a ASP.NET MVC project that has a static class in it to
I have an ASP.NET project which has already some custom fields in it's web.config
I have a master page in my asp.net MVC project, which has code like
I have inhherited a vs2010 c# web project (asp.net). It has a web reference
I have an ASP.NET project which is a front-end to a database. In addition
I have an ASP.Net project using AJAX that I am putting on a server
We have an ASP.Net MVC project that will start with a single web server
We have a large ASP.NET project which has 100s of BLL classes. In our
I have asp.net project which has got GridViews, Buttons, Navigators etc... I have 10-15

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.