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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:09:41+00:00 2026-06-14T11:09:41+00:00

I have a datatable fetching values from a stored procedure written as below: SqlConnection

  • 0

I have a datatable fetching values from a stored procedure written as below:

SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
sqlcon.Open();

DataTable dt = new DataTable("tmp");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();

SqlCommand cmd = new SqlCommand("usp_abc", sqlcon);

cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;

da.Fill(dt);

Now, I need to loop through the datatable and get the values of this datatable and pass it is as a parameter to my stored proc.

  • 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-14T11:09:42+00:00Added an answer on June 14, 2026 at 11:09 am

    I believe such operation is better done in the DB if possible instead of going to the DB for each row in the datatable row collection.

    You can use foreach to loop through the datatable, each DataRow representing a row in the returned result.

    foreach(DataRow row in dt.Rows)
    {
         var col1 = row[0];  //access using column index/position
    
         var firstNameCol = row["FirstName"].ToString();  //access through column name
    }
    

    You can throw more light on what you want to do if it’s possible to move it to DB (using stored procedure)

    • DataTable.Rows

    Update: Passing value to stored proc using command.Parameters

    cmd.Parameters.AddWithValue("@FirstName", firstNameCol);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Datatable which is fetching ~5,50,000 records from database(SQLite). When fetching it
I have: DataTable Table = new DataTable; SqlConnection = new System.Data.SqlClient.SqlConnection(Data Source= + ServerName
I have a DataTable MyDT like below: string MyConString = SERVER= + sConfig_hostname +
I have a datatable that stores location values as such: CTY_CD, STATE_CD, COUNTRY_CD and
I have datatable and I am displaying those values in the datagridview with the
I have a DataTable which is generated from .xls table. I would like to
I am fetching some values from my DB. The columns are of float type
I have a datatable with values consists of more than 12 decimal places (e.g.
I have following code var res = from c in model.Data select new object[]
I have a DataTable containing a list of Id's I get from the DB.

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.