|
Okay. I am not know with this. Can you give me an example how to implement this?
|
|
|
|
|
When you read the data from the datatable, I call it playerTable here:
if (playerTable.Rows[index].IsNull["BirthDay"]) {
... store a value that represents 'no data'
} else {
... get the data
}
---
b { font-weight: normal; }
|
|
|
|
|
Thanx Guffa that will do the trick! (y)
|
|
|
|
|
How about trying this?
dtpBirthday.Value = dsPlayer.Players[0].BirthDay.ToString()== DBNull.Value ? DateTime.Now : dsPlayer.Players[0].BirthDay ;
This is an example of a conditional if statement and will best suit your purpose.
The Conditional Statement
variable = op1 == op2 ? trueValue : FalseValue ;
where:
op1 == op2 is your condition
Life is Music listen to it before it fades away
|
|
|
|
|
Hi Azerax,
I tried something like that but it gives me the following error:
Operator '==' cannot be applied to operands of type 'string' and 'System.DBNull'
That's why I came to codeproject.
|
|
|
|
|
Ohh I am sorry Please note the corrected code as follows:
dtpBirthday.Value = dsPlayer.Players[0]["BirthDay"]== DBNull.Value ? DateTime.Now : dsPlayer.Players[0]["Birthday"].ToString() ;
Where birthday is a field in your dataTable.
Elvis (a.k.a Azerax)
Life is Music listen to it before it fades
|
|
|
|
|
Ohh I am sorry I got it wrong again . Please note the corrected code as follows:
dtpBirthday.Value = dsPlayer.Tables["Players"].Rows[0]["Birthday"]== DBNull.Value ? DateTime.Now : dsPlayer.Tables["Players"].Rows[0]["Birthday"].ToString() ;
Sorry for the trouble...
Elvis (a.k.a Azerax)
Life is Music listen to it before it fades
|
|
|
|
|
Hello,
i've got an issue with objects. I have some code which
looks something like this:
public void X(object o) {
Y.getName(o);
}
public class Y {
public static string getName(Relation r) {
}
public static string getName(object o) {
}
}
when in method X i get a Relation object and I use the overloaded static method
in class Y it always uses the overload that accepts the base-object type. Maybe this
is because the object I get in method X kind of 'wraps' the Relation object in a 'base' -object. Does anyone know how I can manage to get this to work ?
Thanks
with kind regards
Joris
|
|
|
|
|
What method is used is decided at compile time, not run time. Therefore each method call always calls the same method, regardless of the data you use.
You have to type the object to a Relation to use the method that accepts a Relation. Check if the object is a relation:
if (o is Relation) {<br />
Y.getName((Relation)o);<br />
} else {<br />
Y.getName(o);<br />
}
---
b { font-weight: normal; }
|
|
|
|
|
And by the way, this has nothing at all to do with boxing and unboxing, which is about wrapping primitives and structs (things on the stack) in objects (things on the heap), so that they can be treated like objects (for example, this is what happens when you put primitives in an array list).
Matt Gerrans
|
|
|
|
|
i want to do a if loop with the condition
string a;
if(a!=""){}
something like this, but != cannot be used in strings, any alternatives?
|
|
|
|
|
Yes it can if(a != "B"){} would work just fine
|
|
|
|
|
what is wrong with if(a!="") it is suppose to work any way you can use if(!a.Equals(""))
Or you can check the Length of string
MCAD
|
|
|
|
|
binglin wrote:
but != cannot be used in strings
Yes, it can.
It's more efficient to check the length of the string than to compare strings:
if (a.Length > 0)
Also, you never need to create instances of empty stings. There is already one that you can use:
string b = string.Empty;
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote:
Also, you never need to create instances of empty stings. There is already one that you can use:
string b = string.Empty;
Also one another benefit from Guffa suggestion after compare the Length of string
string.Empty abit faster than compare with "" because
"" create temp object
MCAD
|
|
|
|
|
Hi
i have a web service and a web method .
this method doesnt return any thing and perform some task .but it consumes my time ( 1 minute )to do its job.How i can only call the method ( only send a message to do its job) to overcome this problem.
|
|
|
|
|
You could let the web method start the actual job in a different thread, and then immediately return.
---
b { font-weight: normal; }
|
|
|
|
|
But i want after sending message ,i can exit application!
if i use thread i cant.
|
|
|
|
|
Why not?
---
b { font-weight: normal; }
|
|
|
|
|
How do I simulate a ping command ??
And My need is to know IP "156.72.1.30" is reachable or not , if yes, port 3962 opened or not. I do not know which service is running on that port.
love2code
|
|
|
|
|
|
Hi all,
I'working on a windows form c# mdi application.
Sometimes (I can't reproduce the situation) I got a "The object is currently in use elsewhere".
All I can tell is that it always happens in front of a gui event (form closing, form resizing, form activation and so on...).
Does anyone know what the problem can be ?
Thanks
|
|
|
|
|
Hi all!
I'm trying to load several image files into a form.
These files may overlap and can be moved by up, down, left and right button controls.
How can I achieve this? Do I have to use picture boxes? Can one picture box contain several images?
Thanks!;)
|
|
|
|
|
You can load your pictures into an array of type Image or BitMap and then assign the element of the array that contains the picture you want to display to the image property of the PictureBox. Loading the pictures into an array allows you to quickly change the picutures (without have to load each one from a file, all done when you load them into the array)
I think you could also use an ImageList (control), but I'm guessing and have not had much luck with it's implimentation. Last time I used it I have a problem with my pictures being reformatted and never looked into it.
www.lovethosetrains.com
|
|
|
|
|
Thanks, array is a great idea! I never thought of that Newbie here
Regarding PictureBoxes, if I want to load multiple images, I have to use one PictureBox for each correct?
Is PictureBox or using Graphics class a better way to approach this?
|
|
|
|