我是 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();
}
我知道这取决于读者对象,但之后我不知道如何继续。只需要大意...