public User loadUser(int id) { User u = new User(); using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = @"Data Source=kraka.ucn.dk;Initial Catalog=dmai0914_2Sem_6;Persist Security Info=True;User ID=dmai0914_2Sem_6;Password=IsAllowed"; cn.Open(); string strSQL = "Select * from [User] where id = @id"; using (SqlCommand myCommand = new SqlCommand(strSQL, cn)) { myCommand.Parameters.AddWithValue("@id", id); try { SqlDataReader myDataReader = myCommand.ExecuteReader(); if (myDataReader.Read()) { u.name = (string)myDataReader["name"]; u.username = (string)myDataReader["username"]; u.password = (string)myDataReader["password"]; u.email = (string)myDataReader["email"]; u.address = (string)myDataReader["address"]; u.phoneNr = (string)myDataReader["phoneNr"]; u.country = (string)myDataReader["country"]; u.postalCode = (string)myDataReader["postalCode"]; u.salt = (string)myDataReader["salt"]; } } catch (SqlException e) { } } cn.Close(); } // test for null values return u; }
public List<User> loadAllUsers() { userList = new List<User>(); using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = @"Data Source=kraka.ucn.dk;Initial Catalog=dmai0914_2Sem_6;Persist Security Info=True;User ID=dmai0914_2Sem_6;Password=IsAllowed"; cn.Open(); string strSQL = "Select * From [User]"; using (SqlCommand myCommand = new SqlCommand(strSQL, cn)) { try { SqlDataReader myDataReader = myCommand.ExecuteReader(); while (myDataReader.Read()) { User u = new User(); u.name = (string)myDataReader["name"]; u.username = (string)myDataReader["username"]; u.password = (string)myDataReader["password"]; u.email = (string)myDataReader["email"]; u.address = (string)myDataReader["address"]; u.phoneNr = (string)myDataReader["phoneNr"]; u.country = (string)myDataReader["country"]; u.postalCode = (string)myDataReader["postalCode"]; u.salt = (string)myDataReader["salt"]; userList.Add(u); } } catch (SqlException e) { //error userList = null; } } cn.Close(); } return userList; }
public void RegisterUser(User user) { }