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 8783745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:54:15+00:00 2026-06-13T20:54:15+00:00

this is a method i was reading about @MSDN , my question is if

  • 0

this is a method i was reading about @MSDN ,
my question is if for an example i would like to use it on a stored procedure
with the fact that the query of that stored procedure is already specifying columns to select from the table like following :

SELECT Columnsome, columnother, , , , ...FROM thisSQLdbTable

though i would like to implement the approach of that specific method , it seems very advanced from a little research i have made on
“the best way” available to extract data from SQL Server into Asp.net DataTable.

public static DataTable GetCustomerData(string dataSetName,
string connectionString)
{
DataTable table = new DataTable(dataSetName);

using (SqlConnection connection = new SqlConnection(connectionString))
{
    SqlDataAdapter adapter = new SqlDataAdapter(
        "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", connection);

    DataTableMapping mapping = adapter.TableMappings.Add("Table", "Customers");
    mapping.ColumnMappings.Add("CompanyName", "Name");
    mapping.ColumnMappings.Add("ContactName", "Contact");

    connection.Open();

    adapter.FillSchema(table, SchemaType.Mapped);
    adapter.Fill(table);
    return table;
}

}

or is it not the method to use if i am querying via SP that specifies the selected column

i could actually drop that stored procedure if it is not requiered to select /specify columns

the stored procedure is doing a specific calculation and updates the table with results of calculation then i am switching it’s “MODE” to select results from the table that was updated.

what i did is recyceling (; giving it a parameter (bit type)
stored procedure then asks for the value of supplied bool / bit Parameter,
if its is status true it updates (doing its original task it was made for)

if its false its doing a select oporation so i am using it as i would with 2 separated commands

but now that i have search for a better way to extract data from db into a Data table

i give up on the two way SP and i will make a selection via the exaple above if they’re not intended to be used thogether as with my current SP that does preselection when servs the GetCustomersData() above.

So the question is do i need to let the function to make the selection or can i serve it with my sp ready made selection to implemet it with GetCustomersData() in the way that it will only do rest of task and only mapp the columns that was preselected

  • 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-13T20:54:17+00:00Added an answer on June 13, 2026 at 8:54 pm

    Still a bit confused on your actual requirement but here goes:

    I See you are using a direct query in your C# code, ‘best way’ would be to make a SP out of it then say:

    SqlCommand command = conn.CreateCommand();
                SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "sp_GetCustomerData";
    

    Then after you have added parameters if needed do:

                conn.Open();
                sqlAdapter.Fill(dtResult);                
                conn.Close();
    

    Where dtResult is Datatable.
    So you do not need to do any mapping in this case, and since you are using a SP from the Database it will work faster than your direct query and you can change the query logic any time without the need of re deploying your code.

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

Sidebar

Related Questions

I was reading this MSDN article about the usage of properties and methods in
I have this situation where I am reading about 130K records containing dates stored
Reading from MSDN: A delegate is a type that references a method. Once a
I've been reading about the this pointer on various sites (e.g. the MSDN manuals)
I'm reading the msdn library topic about genrics . There is an example of
I was reading this article about Dynamic Objects in C# 4.0 . In that
I've been reading on Generics lately, and I came across this method: protected <V>
I was reading this answer and trying to copy the method used there, but
I was just reading this line: The first thing the format() method does is
While reading this class BitmapFactory I noticed that almost all methods inside are static.

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.