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

  • Home
  • SEARCH
  • 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 8762215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:28:13+00:00 2026-06-13T15:28:13+00:00

I am using the followng code to bind to an ASP.NET DataGrid. I have

  • 0

I am using the followng code to bind to an ASP.NET DataGrid. I have the following and it works but wondering if this is the best approach. Few things that concern me is that I did not nee to Open the connection and also I did not make use of the DataReader. Note that this is written in my code behind page.

             string strConn =  ConfigurationManager.ConnectionStrings["SQL1"].ConnectionString; 
             SqlDataSource DataSource1 = new SqlDataSource();  
             DataSource1.ConnectionString = strConn;
             DataSource1.SelectCommand = "SELECT * FROM tblTruck where LocId = @LocID ";     

             DataSource1.SelectParameters.Add(new Parameter("LocId", System.TypeCode.String, value));                 
             Grid1.DataSource = DataSource1.Select(DataSourceSelectArguments.Empty); 
             Grid1.Rebind();   
  • 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-06-13T15:28:14+00:00Added an answer on June 13, 2026 at 3:28 pm

    In this case the DataSource control handles the internal logic of establishing a connection, reading off it, and parsing the return. this in itself is very handy, but causes problems if you need more control.

    Stylistically, it is never ever a good idea to have SQL code hardcoded in your UI, though it is good you are using a parameter instead of concatenating.

    overall there is no “best approach”. based on factors like maintenance/change, code vulnerability, performance, reliability, display complexity, etc, your solution should be tailored to your problem.

    Personally I don’t like datasource controls, but they can be useful for grid work when you don’t want to spend a lot of time configuring the grid.

    SQLCommands are very very fast and optimal, but you have to write an maintain a lot of code to use them, and it can be somewhat brittle.

    DataAdapters/DataReaders/DataTables/DataSets are somewhat easier to write an maintain than SQLCommands, but they can be cumbersom in memory, and often don’t dispose correctly.

    Linq/ENF both make writing and maintaining easy, but sometimes they leave you debugging issues with their own generated sql rather than your own, and are generally slower at execution (often by a not-insignifigant amount).

    Hope that helps answer your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems simple but I just cannot get it. I have an asp.net page,
If I have the following ASP.NET code (it's not complete - obviously there's a
I am using an ASP.NET/C# DataList . <asp:DataList ID=EquipmentList RepeatColumns=5..... I have the following
Given the following lines of code which is using JQTOUCH: $('#customers').bind('pageAnimationEnd', function(e, info){ if
I am using following code to show a spinning wheel: $(#loading) .hide() .ajaxStart(function(){ $(this).show();
I am using following code to get bitmap from url. This function is used
Background: I am using ASP.NET 2.0 (with C#) and the code below is embedded
I have built a dynamic gridview using the following code grdVariants.Columns.Clear(); int i =
I have a DataGrid control binded to DataTable using the following: dataGrid1.ItemsSource = dataTable1.DefaultView;
I am using Entity Framework with asp.net mvc, but I don't think mvc plays

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.