public static User getUser(string login) { SqlConnection myConnection = null; ConnectionStringSettings connectionSetting = getConnectionSettings("sql01"); string connectionStr = "Data Source = " + connectionSetting.ConnectionString; User _user = new User(); //SqlDataAdapter _sqlDataAdapter = null; DataTable userTable = new DataTable(); try { myConnection = new SqlConnection(connectionStr); myConnection.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE login=@login", myConnection); //SqlParameter param = new SqlParameter(); cmd.Parameters.Add(new SqlParameter("@login", login)); //cmd.Parameters.Add(new SqlParameter("@login", SqlDbType.VarChar, 100,login)); SqlDataAdapter _sqlDataAdapter = new SqlDataAdapter(cmd); // _sqlDataAdapter.InsertCommand = cmd; _sqlDataAdapter.Fill(userTable); DataRow _dataRow = userTable.Rows[0]; _user = convert_DataRowToUser(_dataRow); return _user; } finally { // close connection if (myConnection != null) { myConnection.Close(); } } }
private static User convert_DataRowToUser(DataRow _dataRowUser) { User itemUser = new User(); itemUser.FirstName = _dataRowUser.Field<string>("first_name"); itemUser.Hash = _dataRowUser.Field<byte[]>("hash"); itemUser.LastName = _dataRowUser.Field<string>("last_name"); itemUser.Login = _dataRowUser.Field<string>("login"); //itemUser.Parent_User_id = null; itemUser.Salt1 = _dataRowUser.Field<byte[]>("salt1"); itemUser.Salt2 = _dataRowUser.Field<byte[]>("salt2"); itemUser.User_ID = _dataRowUser.Field<Guid>("user_id"); return itemUser; }