Thanks that's the one thing I didn't try, and it worked :)
Etienne_123
Posts
-
How to get value from PropertyInfo -
How to get value from PropertyInfoList<PropertyInfo> properties = new List<PropertyInfo>();
properties.AddRange(someObject.GetType().GetProperties());
var pInfo = properties.Find(prop => prop.Name.Equals("someName"));This allows me to retrieve the appropriate PropertyInfo object
-
How to get value from PropertyInfoThis is a sample of a similar method I`m trying to use:
private string GetValueFromProperty(PropertyInfo pInfo)
{
return pInfo.GetValue(this, null).ToString();
//return pInfo.GetValue(null, null).ToString();
//return pInfo.GetValue(pInfo, null).ToString();
//return pInfo.GetValue(null, new object[] {}).ToString();
}The lines that are commented out are other options I've tried. All of the above gives me the following error:
"Object does not match target type"
-
How to get value from PropertyInfoIs it possible to get the actual property value from a PropertyInfo object? I've tried the GetValue method with various parameters, but nothing works. I just get exceptions
-
Only show decimals if there are anyI`m not too concerned with precision. At the moment it works perfectly - If I do have decimals it keeps the decimals and if I don't then it shows the whole number. I just tested this by creating a random decimal of 4.4567, converted it to a double and the value stayed the same
-
Only show decimals if there are anySo I found a way of doing this. If you use Decimal.ToDouble it seems to do the job :)
-
Only show decimals if there are anyHi Is it possible to have a variable ONLY show decimals if it does have decimal values? E.g. if the value comes back grom the database as 500 then instead of showing 500.00, it should just show 500. If it comes back as 500.55, then it should show 500.55. Please note that I do not want to use string formatting here as I want to retain the decimal type for sorting purposes.
-
SQL Function problemAnyone have any ideas why this won't work? I just want to check whether some fields are not null before I set the value of
@UserName
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = Object_ID('[dbo].[__Reporting_GetUserName]')
AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
DROP FUNCTION [dbo].[__Reporting_GetUserName]
ENDBEGIN
EXEC dbo.sp_executesql N'
CREATE FUNCTION [dbo].[__Reporting_GetUserName] (@userId int)
RETURNS VARCHAR(MAX)
AS
BEGINDECLARE @UserName VARCHAR(MAX)
SET @UserName =
(
IF [FirstName] is not null
BEGIN
SELECT [FirstName] + '' '' + [LastName]
FROM __User
WHERE Id = @userId
END
)RETURN @UserName
END
'
END -
SQL View returning different resultsHi I have a SQL view that returns different results depending on how I run it. If I run it in Design mode, all of the records in some of the columns come back as NULL. However, when I SELECT TOP 1000 rows from the view, the records in these columns are returned with the correct values. Any ideas why this happens?
-
Problem matching name using RegexThanks I only noticed that now.
-
Problem matching name using RegexHi I seem to be having a problem matching names using Regex, even though it works perfectly in Expresso. The goal is to match only the name in the string below. Here is the Regex I`m using:
\b[a-z][A-Z]*\b\s*\b[a-z][A-Z]*\b
..and here is the string I`m matching:"JOHN DOE john@random.net(H) 04377777746, (W) 0444444543, (F) 022222223, (M) 082343222;"
Like I said, in Expresso it matches the full name, but when I use:MatchCollection NameCollectionRegex = Regex.Matches(contactDetails, @"(\b[a-z][A-Z]*\b\s*\b[a-z][A-Z]*\b)");
orMatch m = Regex.Match(contactDetails, @"(\b[a-z][A-Z]*\b\s*\b[a-z][A-Z]*\b)");
it doesn't return any matches. Anything I could be doing wrong? -
Regex to retrieve phone numbers -
Regex to retrieve phone numbersThanks that did help :)
-
Regex to retrieve phone numbersHi I need some help regarding Regex as my knowledge of it is rather poor. I have a string like the following:
"John Doe, john@bleh.com, (H) 0412623423234, (W) 1290034589345, Jane Doe, jane@bleh.com, (H) 041235423234, (W) 1290034589345"
What I need to do is to retrieve each Email address as well as each Home and Work number separately. After retrieving the separate values I would then like to store the related ones together as one comma-separated property like in the following example:customer.Email = "john@bleh.com,jane@bleh.com"; customer.HomePhone = "0412623423234,041235423234";
I already used a Regex pattern to retrieve all the email addresses in the string, but it seems to be a bit more tricky with the different phone numbers. Any advice/help? -
Using the same table more than once in a SQL ViewI have a MandateFeature table that contains two Id's , MandateId and FeatureId. Each of these are foreign keys from two different tables (Feature and Mandate). If a mandate (house) contains 3 bedrooms and the Id for bedroom is 5, then the entries in the MandateFeature table will look something like this: MandateId | FeatureId ---------------------- 2, 5 2, 5 2, 5 If a mandate (house) has 2 bathrooms and the Id for bathroom is 6, then the table would look something like this: MandateId | FeatureId ---------------------- 2, 5 2, 5 2, 5 2, 6 2, 6 What I want to do, is to count the number of bedrooms as well as the number of bathrooms and then display it as follows: Bedrooms: 3 Bathroom: 2 So I get it working using this:
SELECT DISTINCT dbo.__Mandate.Id, COUNT(BedroomFeature.FeatureId) AS Bedrooms, dbo.__MandateType.MandateType, dbo.__Mandate.ErfSize
FROM dbo.__Mandate INNER JOIN
dbo.__MandateType ON dbo.__Mandate.MandateTypeId = dbo.__MandateType.Id LEFT OUTER JOIN
dbo.__MandateListing ON dbo.__Mandate.Id = dbo.__MandateListing.MandateId LEFT OUTER JOIN
dbo.__MandateFeature AS BedroomFeature ON dbo.__Mandate.Id = BedroomFeature.MandateId AND BedroomFeature.FeatureId =
(SELECT Id
FROM dbo.__Feature AS __Feature_1
WHERE (Feature = 'Bedroom')) LEFT OUTER JOIN
dbo.__Feature ON BedroomFeature.FeatureId = dbo.__Feature.Id
GROUP BY dbo.__Mandate.Id, dbo.__MandateType.MandateType, dbo.__Mandate.ErfSize..but this of course only displays the number of bedrooms. As soon as I duplicate this part:
LEFT OUTER JOIN
dbo.__MandateFeature AS BedroomFeature ON dbo.__Mandate.Id = BedroomFeature.MandateId AND BedroomFeature.FeatureId =
(SELECT Id
FROM dbo.__Feature AS __Feature_1
WHERE (Feature = 'Bedroom')) LEFT OUTER JOIN
dbo.__Feature ON BedroomFeature.FeatureId = dbo.__Feature.Idand modify it to this:
LEFT OUTER JOIN
dbo.__MandateFeature AS BathroomFeature ON dbo.__Mandate.Id = BathroomFeature.MandateId AND BathroomFeature.FeatureId =
(SELECT Id -
Using the same table more than once in a SQL ViewHi Is it possible to use one table more than once when creating a SQL VIEW? For example, the tables I`m using store data about houses and it's features (e.g. bathrooms, bedrooms, etc), and what I want to accomplish is to display the number of bathrooms as well as the number of bedrooms in one view. To do this I`m using the COUNT function to count the number of FeatureId's where the FeatureName = 'Bathroom' etc. as shown below:
SELECT DISTINCT dbo.Mandate.Id, COUNT(BedroomFeature.FeatureId) AS Bedrooms, dbo.MandateType.MandateType, dbo.Mandate.ErfSize
FROM dbo.Mandate INNER JOIN
dbo.MandateType ON dbo.Mandate.MandateTypeId = dbo.MandateType.Id LEFT OUTER JOIN
dbo.MandateListing ON dbo.Mandate.Id = dbo.MandateListing.MandateId LEFT OUTER JOIN
dbo.MandateFeature AS BedroomFeature ON dbo.Mandate.Id = BedroomFeature.MandateId AND BedroomFeature.FeatureId =
(SELECT Id
FROM dbo.Feature AS Feature_1
WHERE (Feature = 'Bedroom')) LEFT OUTER JOIN
dbo.Feature ON BedroomFeature.FeatureId = dbo.Feature.Id
GROUP BY dbo.Mandate.Id, dbo.MandateType.MandateType, dbo.Mandate.ErfSizeThis displays perfectly with the number of bedrooms. How can I show an extra column for the number of bathrooms? I tried adding the features table again and giving it a different alias, but somehow that didn't give me the desired results
-
Making a generic progress formThanks for all the replies :) I managed to sort it out
-
Better progressbar?Hi In my application I allow for users to upload documents to a server via a web service. I recently created a progress form to show the progress of the documents being uploaded by incrementing a progressbar and updating some labels. However, the progress bar increments are equal to the size of the current document, so it updates in blocks. Is there any way to get the current byte or kilobyte being uploaded and increment the progress bar with that to create a better looking progress bar that continuously updates?
-
Making a generic progress formHi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:
public ProgressForm()
{
SomeUserControl._updateProgressbarDelegate =
new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
}This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that
updateProgressbarDelegate
is actually a delegate in the form/usercontrol I just passed through? If I do something like this:public ProgressForm(UserControl callingControl)
{
//do something with callingControl
}..then
updateProgressbarDelegate
will obviously not show up in intellisense when typingcallingControl.
because it doesn't know of what typecallingControl
is. Could anyone please provide some help or hints? -
Update progress bar on another formI've realised that this method won't work due to various other methods that gets called from the long operation, methods that change controls etc. This raises the "control accessed from a different thread..." error. I cannot change these methods becauses it is part of a rather tightly coupled project. There must be a way to simply update the progressbar on the LoadingForm using a thread?!