0

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;}
    ....
}
  1. 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.

Syntax Rommel
  • 932
  • 2
  • 16
  • 40
  • replace the data retrieval from sql server with that from DB2. the rest remains the same – Chetan Oct 17 '18 at 00:49
  • I tried to substitute those sql to DB2Command by importing IBM.Data.DB2 but there still missing that cannot be read, could you give me sample reference? – Syntax Rommel Oct 17 '18 at 01:15

0 Answers0