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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:24:27+00:00 2026-06-13T18:24:27+00:00

I am sending a standard Sql select statement to my Sql box via the

  • 0

I am sending a standard Sql select statement to my Sql box via the SqlDataAdapter, then populating a DataSet object.

I can access the rows in the resulting DataSet, but how can I convert the DataSet into a List which can be returned to the MVC View. i.e. I’m assuming a List object is the best way to handle this.

Here’s my controller c# code:

public class QAController : Controller
{

    private readonly static string connString = ConfigurationManager.ConnectionStrings["RegrDBConnection"].ToString();
    private readonly static SqlConnection sqlConn = new SqlConnection(connString);
    private readonly static SqlCommand sqlComm = new SqlCommand();

    public ActionResult Index()
    {
        DbRegressionExec();
        return View();
    }
    public static void DbRegressionExec()
    {
        // SELECT TABLE CONTENTS FROM SQL !!
        RegressDB_TableList regresDB = new RegressDB_TableList();
        string sqlStr = "select * from [RegressionResults].[dbo].[Diff_MasterList] order by TableName";

        // POPULATE DATASET OBJECT
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sqlStr, sqlConn);
        da.SelectCommand.CommandType = CommandType.Text;
        sqlConn.Open();
        try
        {
            da.Fill(ds, "RegresDB");
        }
        catch (Exception e)
        {
            throw;
        }
        finally
        {
            sqlConn.Close();
        }

       // I can iterate thru rows here, but HOW DO CONVERT TO A LIST OBJECT ????

        int numRows = ds.Tables["RegresDB"].Rows.Count;
        for (int i = 0; i < numRows; i++)
        {
            string tblName = ds.Tables["RegresDB"].Rows[i].Field<string>("TableName");
        }

        //List<RegressDB_TableList> masterList = regresDB.RegresTableList.ToList(); //not working !!
        //var masterList = regresDB.TableName.ToList(); //

    }

}

and a simple class I may need to make this happen:

namespace RegressionMvc.Models
{
  public class RegresDB_TableName
  {
     public string TableName { get; set; }
  }
  public class RegressDB_TableList
  {
     public List<RegresDB_TableName> RegresTableList { get; set; }
  }

}

In the end, I’m trying to figure out the best way to handle DataSet results from Sql Server and how to make them back to an MVC View.

I can probably go with jQuery and Json, meaning just convert the data fields to Json and return to JQuery, but I’m sure there are several ways to handle Sql based result sets.

Thanks in advance for your advice….

Best,
Bob

  • 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-13T18:24:29+00:00Added an answer on June 13, 2026 at 6:24 pm

    Short answer

    Directly answering your question:

    var tableList = new List<RegresDB_TableName>();
    int numRows = ds.Tables["RegresDB"].Rows.Count;
    for (int i = 0; i < numRows; i++)
    {
        string tblName = ds.Tables["RegresDB"].Rows[i].Field<string>("TableName");
        tableList.Add(new RegresDB_TableName() { TableName = tblName };
    }
    
    return View(tableList);
    

    Long answer (that’s actually shorter)

    Try out dapper-dot-net.

    Your code could change to something like:

    string sqlStr = "SELECT * FROM [RegressionResults].[dbo].[Diff_MasterList] ORDER BY TableName";
    return sqlConn.Query<RegresDB_TableName>(sqlStr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When sending data via POST or GET with jQuery you use for format {
I am sending date values from C# application via JSON but instead of a
Does anyone know a standard way to batch http requests? Meaning - sending multiple
I am using facebook new requests 2.0 for sending apprequests via application. Now I
I am sending an email via php/html to a gmail address. The email displays
I'm sending users, once logged into my app to the standard users#show page. def
On a standard LAMP application i am sending people to my 404 page using
I has a fairly standard method that base64-encodes a string prior to sending that
I have some applications, and standard Unix tools sending their output to named-pipes in
I have the standard code for sending out http request. Using http.globalAgent. I set

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.