我是C#的新手。我如何在Razor視圖中顯示SQL?如何將結果導入視圖
// GET: /ReportData
public ActionResult Index()
{
using (SqlConnection connection = new SqlConnection(@"Data Source=xxx.xxx.xxx.xxx;Initial Catalog=xxxxxx;Persist Security Info=True;User ID=xxxxx;Password=xxxxx"))
{
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = @"select * from ProjectManagement as p
join Implementation as i on p.JobNumber = i.JobNumber
join Divisions as d on i.Division = d.Division
where p.ProjectStatus = 'Active'"
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// process result
reader.GetValue(0);
reader.GetValue(1);
reader.GetValue(2);
reader.GetValue(3);
reader.GetValue(4);
reader.GetValue(5);
}
}
}
}
return View();
}
我明白這取決於讀者對象,但在此之後,我不知道如何進行。只需要...
首先使用僞數據。然後您將瞭解如何從sql中獲取結果並顯示這些結果 – Haritha