Using ASP.NET MVC with C#, Is there a basic reference that I can start up on creating connection string for DB2 in controller then loads it to my view. I just currently referring to this link but the only difference is I need DB2 rather than SQL.
1.Model
public class Student
{
public string FirstName {get;set;}
public string LastName {get;set;}
public string Class {get;set;}
....
}
Controller
public ActionResult Students() { String connectionString = "<THE CONNECTION STRING HERE>"; String sql = "SELECT * FROM students"; SqlCommand cmd = new SqlCommand(sql, conn); var model = new List<Student>(); using(SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { var student = new Student(); student.FirstName = rdr["FirstName"]; student.LastName = rdr["LastName"]; student.Class = rdr["Class"]; .... model.Add(student); } } return View(model);
}
will appreciate your suggestions and comments.