private void writeToDB(StudentDetail student) { TargetDB db = new TargetDB("Yuwa", "anly4s85vg.database.windows.net", "Yuwa", "Welcome_1234"); var queryString = string.Format("INSERT INTO StudentDetails(FirstName, LastName, Gender) VALUES ('{0}','{1}','{2}')", student.FirstName, student.LastName, student.Gender); db.ExecuteNonQuery(queryString); }
public ActionResult About() { TargetDB db = new TargetDB("Yuwa", "anly4s85vg.database.windows.net", "Yuwa", "Welcome_1234"); List <DataTable> result = db.ExecuteQuery("Select * from StudentDetails"); string studentList = ""; List <StudentDetail> students = new List <StudentDetail>(); /* * [id] [int] NOT NULL, * * [O365ID] [uniqueidentifier] NULL, * [Birthdate] * [smalldatetime] * NOT NULL, * [Gender] [char](1) NULL, * [Address] [nvarchar] (1000) NULL, * [Student Pic] [nvarchar] (100) NULL, * [Blood Group] [char](3) NULL, * [Village] [nvarchar] (100) NULL, * [Phone] [int] NULL, * [DOJ_Yuwa] [smalldatetime] NULL, * [Familyid] [int] NULL, * [firstname] [nvarchar] (255) NULL, * [lastname] [nvarchar] (255) NULL, * [middlename] [nvarchar] (255) NULL, * [is_student] [bit] NULL, * [is_coach] [bit] NULL, * [schoolid] [int] NULL, * [teamid] [int] NULL, * [classid] [int] NULL, * [nickname] [nvarchar] (255) NULL,*/ foreach (DataRow row in result[0].Rows) { students.Add(new StudentDetail() { FirstName = GetValue <string>(row, "firstname", ""), LastName = GetValue <string>(row, "lastname", ""), Gender = GetValue <string>(row, "Gender", ""), NickName = GetValue <string>(row, "nickname", ""), Birthdate = (DateTime)Convert.ChangeType(row["Birthdate"], typeof(DateTime)), DOJ_Yuwa = GetValue <DateTime>(row, "DOJ_Yuwa", DateTime.MaxValue), Address = GetValue <string>(row, "Address", ""), BloodGroup = GetValue <string>(row, "Blood Group", ""), Village = GetValue <string>(row, "Village", ""), Phone = GetValue <string>(row, "Phone", ""), IsStudent = GetValue <bool>(row, "is_student", true), IsCoach = GetValue <bool>(row, "is_coach", false), }); } ViewBag.Message = "studentList"; return(View(students)); }