public UserProfileEntity GetUserProfileByUserName(string sUserName) { IEnumerable <UserProfileEntity> list = null; string sqlStatement = "SELECT TOP 1 * FROM UserProfile WHERE UserName=@UserName " + Environment.NewLine; using (DbCommand sqlCmd = DatabaseProvider.GetSqlStringCommand(sqlStatement)) { DatabaseProvider.AddInParameter(sqlCmd, "UserName", DbType.String, sUserName); // Call the ExecuteReader method with the command. list = Connection.Query <UserProfileEntity>(sqlStatement, new { UserName = sUserName }, Transaction); } return(list.FirstOrDefault <UserProfileEntity>()); }
public int AddOrUpdateUserProfile(int iUserId, string sUserName, string sFullName, string sPosition, string sPhone) { // Read data with a SQL statement that accepts one parameter prefixed with @. string sqlStatement = "DELETE FROM UserProfile WHERE UserId=@UserId " + Environment.NewLine; sqlStatement += "INSERT INTO UserProfile(UserId,UserName,FullName,Position,Phone) values(@UserId,@UserName,@FullName,@Position,@Phone)"; int result = -1; // Create a suitable command type and add the required parameter. using (DbCommand sqlCmd = DatabaseProvider.GetSqlStringCommand(sqlStatement)) { DatabaseProvider.AddInParameter(sqlCmd, "UserId", DbType.Int32, iUserId); DatabaseProvider.AddInParameter(sqlCmd, "UserName", DbType.String, sUserName); DatabaseProvider.AddInParameter(sqlCmd, "FullName", DbType.String, sFullName); DatabaseProvider.AddInParameter(sqlCmd, "Position", DbType.String, sPosition); DatabaseProvider.AddInParameter(sqlCmd, "Phone", DbType.String, sPhone); result = DatabaseProvider.ExecuteNonQuery(sqlCmd); } return(result); }