我希望使用MVC内部的SQL数据适配器功能来显示项目内部查询字符串的结果。我是使用sql适配器功能的新手,但我想习惯它。简单地说,我需要知道在控制器中放什么,如果我需要创建一个模型,以及在我的视图中放置什么。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace NewHoyaIntranet.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
DataSet data;
DataTable table;
using (SqlConnection connection = new
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HUT"]
.ConnectionString))
{
connection.Open();
SqlCommand select = new SqlCommand("SELECT * FROM HUT.dbo.XREF_HIOI_LensStyle_HTL", connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = select;
data = new DataSet();
adapter.Fill(data, "HUT.dbo.XREF_HIOI_LensStyle_HTL");
table = data.Tables[0]; //is the [0] really correct?
}
return View(/* Right now nothing is returning in any view/ how do i tie the view in? */);
}
}
}