|
DateTime dateRented = rental_InvoiceTableAdapter1.getTimeRentedbyInvoiceNo(int.Parse(txtInvoiceNo.Text));
I can't figure out why I'm getting this exception thrown by this code. I'm trying to collect a single cell from the DateTime column "Time_Rented" using a SQL statement. The SQL statement works fine in the query builder, so it has to be something in the C# code.
The entire error message is:
"Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists ( are you missing a case?)"
Both sides of the statement are DateTime, aren't they? I don't understand why it can't convert it.
Please help!
|
|
|
|
|
Lodeclaw wrote: System.DateTime?
What is System.DateTime? ?
I have only heard of System.DateTime .
Try removing the "?".
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
HAI
CAN HAS STDIO?
PLZ OPEN FILE "SIGNATURE.TXT"?
AWSUM THX
VISIBLE FILE
O NOES
INVISIBLE "ERROR!"
KTHXBYE
|
|
|
|
|
That's confusing me, as well. I didn't type System.DateTime? anywhere. If I had typed it incorrectly the debugger would have notified me when I typed it. I'll do a search for it, anyway.
|
|
|
|
|
It's a nullable datetime. int? is a nullable int, for example.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Look closely at the message. DateTime? is a nullable DateTime. You'll have to do the explicit conversion
[EDIT] or alternatively declare you date rented as the nullable DateTime? type.
Alan.
|
|
|
|
|
I've been trying to do the explicit conversion. How do I know what the explicit conversion is? I've tried DateTime.Parse the query results as a string and I've tried Convert.DateTime . Can you offer any other possibilities?
|
|
|
|
|
DateTime? is short-hand for Nullable<DateTime> , using the Nullable<T> class introduced in .NET Framework 2.0. The Nullable types are actually a class that is a wrapper around a value type. To get the underlying value from a Nullable<T> , use the Value property like so:
DateTime dateRented = rental_InvoiceTableAdapter1.getTimeRentedbyInvoiceNo(int.Parse(txtInvoiceNo.Text)).Value;
Or you can declare dateRented as Nullable<DateTime> (same as DateTime? ) rather than a normal DateTime , like so:
DateTime? dateRented = rental_InvoiceTableAdapter1.getTimeRentedbyInvoiceNo(int.Parse(txtInvoiceNo.Text));
OR
Nullable<DateTime> dateRented = rental_InvoiceTableAdapter1.getTimeRentedbyInvoiceNo(int.Parse(txtInvoiceNo.Text));
The message really means that the getTimeRentedbyInvoiceNo() function is returning a DateTime? and you are trying to stuff that return value into a DateTime ; and they are two different types.
Hope in one hand and poop in the other; see which fills up first. Hope and change were good slogans, now show us more than words.
|
|
|
|
|
I tried those and even though the debugger is ok with them, and the other conversions I've tried, I get an exception telling me the input value is not in the correct format.
|
|
|
|
|
Lodeclaw wrote: I get an exception telling me the input value is not in the correct format.
This may be a different problem now. Where did the exception arise and do you know that the result of int.Parse is valid input for your function?
Alan.
|
|
|
|
|
For some reason the query that fills the txtInvoiceNo textbox is not yielding a result, so my input is an empty string. I'll have to figure out why that is.
In any case, this problem is solved, then. Thanks everyone for helping this poor noob. I learned some new things.
|
|
|
|
|
I'm sorry about my English.But I wish you guys can understand what I said.
I wanna made a modal popup window when the application is executing.
Show some information to user,maybe execute message like "please wait..." or a progress bar something.
How to create a modal dialog during execution in winform?Give me sample source code would be better.
The Main Form will stoped execute when Form.ShowDialog(). I need show the popup form,and the main form still execute.
like this:
void subA()
{
ShowExecuteDialog(); //when show this popup dialog,still execute functionA,b,c,d..
FunctionA();
FunctionB();
FunctionC();
FunctionD();
CloseExecuteDialog();
}
modified on Thursday, February 5, 2009 5:14 AM
|
|
|
|
|
well i assume you can create a form and show that from another form?
well when you show the 'pop-up' form just use form.ShowDialog(); that will make it the only focusable form and well wait for user to click a button to close. On which you need to handle the button click and either .Hide() or .Close() the form. If you want to access propoerties from the form then you will need to use .Hide() so it doesnt dispose of all data
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
you can show the any other form as modal dialog by calling showdialog method and passing the current form as parent.
Form messageForm = new Form();
messageForm.ShowDialog(this);
Be careful, there is no Undo Button(Ctrl+Z) in life.
|
|
|
|
|
No.If just showDialog.The Main Form stoped execute.I need show the popup form,and the main form still execute.
|
|
|
|
|
Ummm, you wanted to show a Modal Dialog. The UI thread on the form that launched the modal stops executing until the modal dialog is dismissed. That's the expected behavior.
If you have to have elements on the main form still responsive to the user, you have show the dialog as a normal form, not modal. If you just have code in the main form that needs to execute without user or UI interaction, then you have to move that code to a seperate thread, then you can show your other dialog modal.
|
|
|
|
|
Hi
Let's think that there is an application which asks you your name at the first start. You enter it and it saves it. Next time you start the application, it doesn't ask your name. It says "Hello ....." .
But it doesn't save your name to registry nor a file. Is this possible? And how can I do this?
Actually this is just a simple example to tell you what I want to do. In short I want to save a string into the EXE, but it should be changeble by the same application.
Thanks.
|
|
|
|
|
Ive never done it, and dont know if possible but i can offer a theory that may lead you somewhere:
Lets say for example you hardcode a string that is 100 chars long. When you compile you application that string is stored in the .exe somewhere. Now if you could find out how .exe are compiled you may be able to find the byte range for that hardcoded value somehow. Then maybe you could write what ever string to that byte range and it would save... Theoretically.
Of course you will have to get around a write issue, when trying to write to the app you are running lol
Maybe, you have a second app that is called, closes the first app, writes the value, then executes the first app again. This is getting rather tediuos thou so im sure you want want to take this route.
But if you do go for it, then dont forget to post any results you find, im sure people would be interested
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Hey, i think im onto something:
I open my .exe in a hex editor (PSPAD) and found the string towards the end of the file. coded in ASCII but split with 0x00 values. can see the offset so know where to edit, problem being modifying the app will prob move the location of the string
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
"coded in ASCII but split with 0x00 values"
That'll be a 16 bit unicode then!
Alan.
|
|
|
|
|
well i assumed it was 16 bit values
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Finding and writing the string to and .EXE file is only one problem. The other problem is that you can't modify an .EXE file if it's currently running. You'll need a second app that takes the parameters and waits for the main .EXE to end, then it can modify the .EXE.
Though, this really isn't a good idea since it's not "version agnostic". If you make a small change to the code and recompile into a new .EXE, the string can very easily change position in the file.
Oh! And if the resulting .EXE is signed with a digital signature, you'll break the security envelope around the .EXE and the code won't run since it will no longer be trusted by the .NET CLR.
|
|
|
|
|
So, instead of my writing into EXE idea. What can I do to change a variable within the application and keep that variable same after I restarted it?
By the way. As an extra idea, how can I make an application which creates another exe from itself with modifying a variable or value of itself?
I have looked for it in Google. But I haven't find satisfactoring answers to my questions.
|
|
|
|
|
SimpleData wrote: So, instead of my writing into EXE idea. What can I do to change a variable within the application and keep that variable same after I restarted it?
There is no alternative, other than saving in the Registry or files external to the .EXE.
SimpleData wrote: As an extra idea, how can I make an application which creates another exe from itself with modifying a variable or value of itself?
The same way you read/write any binary file. Read the .EXE file until you get to the point where the string is, write all that data to a new file, then write the string data, skip reading the string in the source .EXE file, and continue to read the old file to the end, writing it's data to the new file.
But, you have a problem. You STILL need an external application to delete the old .EXE and rename the new .EXE to the old filename. Not, a good solution...
|
|
|
|
|
Ya You Can by creating a variable in the settings of an application.
. on Form load you can call that for ex.
where VariableName is a variable which u need to create in settings of the application
and txtbox1 is a textbox.
public form1()
{
InitializeComponent();
txtbox1.Text = Properties.Settings.Default.VariableName;
}
and on form close you need to save that
private void form1_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Save();
}
Thanks.
Sandy
|
|
|
|
|
You may want to go back and re-read the thread, plus read the documentation on Properties.Settings.
You missed the entire point of the conversation. The OP wanted to save "settings" back to the .EXE instead of a seperate *.settings file. You cannot do that in a "nice" manner. He did NOT want to use an external file, which is what you're proposing doing.
|
|
|
|