How to return a DataSet to a View

前端 未结 4 445
天命终不由人
天命终不由人 2021-01-12 07:55

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,

4条回答
  •  [愿得一人]
    2021-01-12 08:22

    Short answer

    Directly answering your question:

    var tableList = new List();
    int numRows = ds.Tables["RegresDB"].Rows.Count;
    for (int i = 0; i < numRows; i++)
    {
        string tblName = ds.Tables["RegresDB"].Rows[i].Field("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(sqlStr);
    

提交回复
热议问题