|
Hi guys,
Iam trying to update a nullable datetime field in my database using linq-sql.
What ever casting method i have tried i keep getting an error:
"Specified cast is not valid."
Does anyone know how to update a nullable DateTime? field using Linq-Sql? please help me.
I have tried:
myVar.dateredeemed = DateTime.Parse("2010-12-03");
myVar.dateredeemed = (DateTime?)dateTime;
myVar.dateredeemed = DateTime.Now;
I don't really what else i can try because all of the above won't work.
Please help me...
|
|
|
|
|
None of this screams LINQ-to-SQL. Your code should work is myVar.dateredeemed is of type DateTime? if not, that is the source of your problem.
This code works:
DateTime? foo;
foo = DateTime.Now;
However, you should be wary of this:
myVar.dateredeemed = DateTime.Parse("2010-12-03")
For two reasons:
- If the string really comes from user input, they can enter an incorrect value you need to decide whether this should be null or whether the user *must* enter a valid date. Whichever is the correct strategy, incorrect input will throw an error.
- Can the user enter no date, (i.e. "")? If so you code will not result in null
Finally, I'd say one more thing: If you have luxury of changing the database, avoid nulls (especially in databases) like the plague. You end up with problems similar to the one you have here, potential null reference exceptions, and they make coding SQL harder too. That's not to say don't ever use nulls, but you should think several times before using nullable columns. Personally, I'd use one of the SQL min/max dates in place of null to register "unknown", (a bit like replacing and unknown [null] string with "") but others will disagree. A null date (to represent a date not set yet) is one of the few places I think a null column might be pukka. </rant> - Sorry I didn't mean to go on like this .
|
|
|
|
|
Hello,
I have developed a Custom Control for ASP.NET Web Form. In a specific scenario, I dont want to get the Hosting Page's Load event executes. So, I want to clear the Hosting Page's Load Event handler delegates from my custom control. Is it possible ? I dont mind using Reflection, but can you please help me with code snippet example ?
|
|
|
|
|
Hai all,
I need to upload file to server and i am using input file to upload the file, my problem is postedfile.filename is always null.
I have tried using updatepanel and had same problem. Can anyone help me.
|
|
|
|
|
File upload doesn't work under UpdatePanel ByDefault. you need to set PostBackTrigger in <Triggers> Section of UpdatePanel by which you can force a complete PostBack .
Regards,
Hiren.
"The more we give of anything, the more we shall get back." - Grace Speare
(you can consider this quote while giving vote also)
Microsoft Dynamics CRM
|
|
|
|
|
I have tried that too but still it didnt work , the postedfile is null.
|
|
|
|
|
Make sure you are using it under !Page.IsPostBack Condition.
Regards,
Hiren.
"The more we give of anything, the more we shall get back." - Grace Speare
(you can consider this quote while giving vote also)
Microsoft Dynamics CRM
|
|
|
|
|
Actually in my form i had a ultrawebgrid and a template column as button,
when click the button by client side the value ll be assign to the fileupload control and
when i click the upload button the file should be uploaded .
My ultrawebgrid and upload button is inside refresh panel and fileupload is outside the refreshpanel.
|
|
|
|
|
You can't assign the filename in an upload control with javascript. That is a security feature. Otherwise a web site could tell the browser to upload things like password files and steal data.
|
|
|
|
|
T M Gray wrote: You can't assign the filename in an upload control with javascript
He's probably not asking of assigning values rather He wants value inside.
Regards,
Hiren.
"The more we give of anything, the more we shall get back." - Grace Speare
(you can consider this quote while giving vote also)
Microsoft Dynamics CRM
|
|
|
|
|
Yes i need only the value , in client side i am getting the path value but in server side it is null.
|
|
|
|
|
string fn = Path.GetFileName(inputFile.PostedFile.FileName);
string savepath = Server.MapPath("Exports") + "\\" + fn;
inputFile.PostedFile.SaveAs(savepath);
string[] lines = File.ReadAllLines(savepath);
for (int i = 0; i < lines.Length; i++)
{
} ;
Hope that helps..
Later!
|
|
|
|
|
Thnak u for the reply , I ll try it.
|
|
|
|
|
It works, if u need more help hala at me...
|
|
|
|
|
I have tried it but still i am getting null.
PostedFile.FileName is null.
|
|
|
|
|
You might want to take a look at what exactly you are doing in your Page_Load event...you could be reseting the values
of your controls...
Put the code above in a method e.g.:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
UploadFile();
}
}
protected void UploadFile()
{
}
|
|
|
|
|
Hi! I recomend you to use Uploadify control of jQuery! Is the easy and best upload control! for multiple or single, max capacity, type of files, queue files in progress, multi browser, etc! Here[^]
|
|
|
|
|
please help me.
in javascript, how will I get the total if i have quantity * price.
example:
var quantiy =2
var price = 5,000
var total =parseInt(quantity.value) * parseFloat(price.value)
why is it above total returns 10 not 10,000.
and if I will remove the parseInt and parseFloat it returns NaN.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Your code contains couple of errors. Probably you should start JavaScript from beginning. Check the working code.
<SCRIPT language="JavaScript">
<!--
function tot()
{
var quantity =2;
var price = 5000;
var total = parseInt(quantity) * parseFloat(price);
alert(total);
}
</SCRIPT>
Please use appropriate forums to post questions. You should have posted this in Javascript forum.
thatraja |Chennai|India|
Brainbench certifications Down-votes are like kid's kisses don't reject it Do what you want quickly because the Doomsday on 2012
|
|
|
|
|
You do not need to parse either value. They are already both integers
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: You do not need to parse either value. They are already both integers
Yeah, But It will be useful if he put float value in the variable price like with cents (Ex. 5000.50). Also I was mentioned in my message that the code has couple of errors. Thank you.
thatraja |Chennai|India|
Brainbench certifications Down-votes are like kid's kisses don't reject it Do what you want quickly because the Doomsday on 2012
|
|
|
|
|
Well Spotted.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
C#Coudou wrote: var price = 5,000
Write 5000 instead.
It may be counting 5,000 as a 5.000 while parsing, and giving you 5*2 = 10 as OUTPUT.
Regards,
Hiren.
"We owe a lot to the Indians, who taught us how to count, without which no worthwhile scientific discovery could have been made." - Einstein
Microsoft Dynamics CRM
|
|
|
|
|
the following will work fine for your current values...
var quantity = 2;
var price = 5000;
var total = quantity * price;
...not that you do not need to parse either value. If there is a requirement that price will use a decimal value (e.g. 5000.15) then you can do the following...
var quantity = 2;
var price 5000.15;
var total = price * quantity;
...again you will see there is no need for parsing. Notice I have but price before quantity in the second example - although either way will produce the correct result in javascript you may want to note that in other languages (such as C#) price needs to go before quantity in order to avoid a implicit cast to type int - but that's a different subject
Life goes very fast. Tomorrow, today is already yesterday.
modified on Thursday, December 2, 2010 6:29 AM
|
|
|
|
|
Hi,
I have a Imagebutton In a ContentplaceHolder Where I have to Adjust the height and width of the imagebutton with the scrren resolution. for that i had written a javascript..
========================================================
if ((screen.width>1024) && (screen.height>768))
{
var theImg = document.getElementById('Image1');
theImg.width = "100px";
theImg.height = "100px";
}
else
{
var Img = document.getElementById('ctl00_ContentPlaceHolder1_Image1');
Img.width = "50px";
Img.height = "50px";
}
===============================================
in the above code 'Image1' is the id of imagebutton.. im getting null value error when im using the above javascript.
i have also used 'ct100_contentplaceholder_Image1' and '<%image1.ClientID%>' But both of are not worked.
So Please suggest a solution for this problem.
thanks in advance,
vishnu
|
|
|
|