|
If you get the result into a dataset, the set will contain two tables.
If you use a datareader, use the NextResult method to move on to the next resultset.
---
b { font-weight: normal; }
|
|
|
|
|
Great, and then the tables are selected by the index I guess ?
|
|
|
|
|
Yes.
---
b { font-weight: normal; }
|
|
|
|
|
hi dudes;
how are you all ?
when i open my application which is consisting of listbox and button to add values in the listbox but normally when i close the application and reopen it again it gives me new listbox with nothing included inside it that is because every time the application starts the initialize components method create new instance of the listbox that is fine .
but what about if i need to store these values one time and every time i open my application the values still exist ? any help about this the same as the download accelerator as much as the files you download they stored in listbox in the application and if you close the application and reopen it again you can see the values inside the listbox of the downloaded files ? any help to do the same ?
Thanks alot.
Miss With The Best And Die Like The Rest
|
|
|
|
|
snouto wrote:
need to store these values one time
Store them to a file in the Closing-EventHandler of the form,
read them from the file in the form's Load-EventHandler.
<br />
private void MainForm_Load(object sender, System.EventArgs e) {<br />
ReadInitialValue();<br />
}<br />
<br />
private void MainForm_Closing(object sender, System.EventArgs e) {<br />
SaveInitialValues();<br />
}<br />
_________________________________
Please inform me about my English mistakes, as I'm still trying to learn your language!
|
|
|
|
|
check this useful link
http://www.codeproject.com/csharp/PersistentDataStructures.asp
|
|
|
|
|
|
Hello gurus,
I'd like to know how to cancel the Closing event?
I mean, when the user click on the close button of the main window, I ask him if he wants to quit via the MessageBox class. If he answers no or cancel, the window does not close.
Can someone show me a code snippet please?
Thanks for the help.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
Cancelling the closing of a form is quite simple and can be implemented as follows:
protected void Form1_Cancel (Object sender, CancelEventArgs e) {
if (!myDataIsSaved) {
e.Cancel = true;
MessageBox.Show("You must save first.");
}
else {
e.Cancel = false;
MessageBox.Show("Goodbye.");
}
}
Elvis (a.k.a. Azerax)
Life is Music listen to it before it fades
|
|
|
|
|
ok this works
thanks
There is no spoon.
|
|
|
|
|
Hi,
I am using a database. And return the data to a DataSet dsPlayers. Some players have a birthday, which is a DateTime field, and some do not. These have no value so it says <null>. I want to put their birthday to a DateTimePicker dtpBirthday, but when it is <null> I want to give the DateTimePicker the value DateTime.Now.
I have the following code, which is noit working for me.
<br />
if (dsPlayer.Players[0].BirthDay.ToString() == null)<br />
{<br />
dtpBirthday.Value = DateTime.Now;<br />
}<br />
else<br />
{<br />
dtpBirthday.Value = dsPlayer.Players[0].BirthDay;<br />
}<br />
What is the best way to make this if statement?
|
|
|
|
|
You can use the method IsNull of the DataRow class to check if the value in a cell is DBNull.
---
b { font-weight: normal; }
|
|
|
|
|
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
|
|
|
|