12 Replies - 1471 Views - Last Post: 29 January 2011 - 09:29 AM Rate Topic: -----

#1 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Error in using DateTime function:((

Posted 27 January 2011 - 07:27 AM

hi

em developing an application in which i have two tables Request[UName,DateFrom{datetime},DateTo{datetime},Reason] and Date[Date{int},Month{int},Year{int}]...here i fetch date from Date table in dropdownlist and by using Datetime function i set formate and then sent it to Request table. but its giving me an error:((

here is my code

 ProjectContext objCont = new ProjectContext();
        int item1 = int.Parse(dd_LeavDayFrom.SelectedItem.Value);
        int item2 = int.Parse(dd_LeavMonthFrom.SelectedItem.Value);
        int item3 = int.Parse(dd_LeavYearFrom.SelectedItem.Value);

        int item4 = int.Parse(dd_Leav_dayTo.SelectedItem.Value);
        int item5 = int.Parse(dd_Leav_MonTo.SelectedItem.Value);
        int item6 = int.Parse(dd_Leav_YearTo.SelectedItem.Value);

        [color="#DDA0DD"]DateTime dt = new DateTime(item1, item2, item3);[/color]
       [color="#DDA0DD"] DateTime dt1 = new DateTime(item4, item5, item6);[/color]

        Request req = new Request();
        req.UName = txt_LeavEmpName.Text;
        req.DateFrom = dt;
        req.DateTo = dt1;
        req.ReqReason = TextArea.ToString();

        objCont.Requests.Insertonsubmit(req);
        objCont.SubmitChanges();
        Response.Write("Successful!!!!");
    }


i highlighted the statement where its giving me exceptionAttached File  eror.bmp (812.83K)
Number of downloads: 131

edit: uploaded image to an image host:
Posted Image
--insertAlias

This post has been edited by insertAlias: 27 January 2011 - 08:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error in using DateTime function:((

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14417
  • View blog
  • Posts: 57,803
  • Joined: 12-June 08

Re: Error in using DateTime function:((

Posted 27 January 2011 - 07:44 AM

Check out how datetime constructors operate:
http://msdn.microsof...m.datetime.aspx

the input is YEAR, MONTH, DAY... you have it DAY, MONTH, YEAR.
Was This Post Helpful? 1
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Error in using DateTime function:((

Posted 27 January 2011 - 08:16 AM

A suggestion for future posts: Don't put the error message in an attachment that people need to download.
Just select the error message text and copy/paste it into the body of your post.
You have this entire post without actually saying what error you get, and most people aren't going to download attachments from random strangers on the internet.
Was This Post Helpful? 1
  • +
  • -

#4 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 27 January 2011 - 09:29 AM

ok i'll be careful next time:)

n fanx aloadx all above.

i got my mistake:)
Was This Post Helpful? 0
  • +
  • -

#5 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:11 AM

oh again now em getting this error:((


Compiler Error Message: CS0029: Cannot implicitly convert type 'System.DateTime' to 'string'


ProjContext objCont = new ProjContext();
        int item1 = int.Parse(dd_LeavDayFrom.SelectedItem.Value);
        int item2 = int.Parse(dd_LeavMonthFrom.SelectedItem.Value);
        int item3 = int.Parse(dd_LeavYearFrom.SelectedItem.Value);

        int item4 = int.Parse(dd_Leav_dayTo.SelectedItem.Value);
        int item5 = int.Parse(dd_Leav_MonTo.SelectedItem.Value);
        int item6 = int.Parse(dd_Leav_YearTo.SelectedItem.Value);

        DateTime dt = new DateTime(item3, item2, item1);
        DateTime dt1 = new DateTime(item6, item5, item4);

        Request req = new Request();
        req.UName = txt_LeavEmpName.Text;
        [u][b]req.DateFrom = dt;[/b][/u]
        [i][b]req.DateTo = dt1;[/b][/i]
        req.ReqReason = TextArea.ToString();

        objCont.Requests.Insertonsubmit(req);
        objCont.SubmitChanges();
        lbl_LeavSnt.EnableViewState = true;

        


i made it bold where its giving error.

why its happening now:((
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14417
  • View blog
  • Posts: 57,803
  • Joined: 12-June 08

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:21 AM

It is happening because you did not tell the date time to be a string! Try to add a ".tostring()" on the end of your datetime objects.
Was This Post Helpful? 0
  • +
  • -

#7 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:30 AM

but in database....its Datetime datatype of DateFrom and DateTo fields....

even then???
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14417
  • View blog
  • Posts: 57,803
  • Joined: 12-June 08

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:34 AM

I am not sure what this "Request" class is. If it's something existing or something you wrote your own. All I know is if the "DateFrom" method of "req.DateFrom" is not liking a datettime being shoved into it, and instead wants a string then make the date time a string! Check that property (DateFrom) to see what it is!

It probably needs the value converted to string to be transmitted to the DB... but then again I haven't seen that code so it's up in the air.
Was This Post Helpful? 0
  • +
  • -

#9 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:45 AM

em getting you. when i did it separatly it worked perfect but now i merged it with my application its giving eror... n now i add toString()and its working:) dont knw the reason but working.

making me rash non stable attitud:(
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14417
  • View blog
  • Posts: 57,803
  • Joined: 12-June 08

Re: Error in using DateTime function:((

Posted 27 January 2011 - 10:54 AM

It works because the "DateFrom" *only* accepts strings. Datetime is not a string until you call the "toString" method that outputs the date time into a string.

That is sent over your connection and when inserted into the database, the DB checks to make sure it can extract a date and time from the string (things are in the right location, etc). If it can then it makes the string go to date time on that end. If not then it errors out.

Pretty straight forward.
Was This Post Helpful? 0
  • +
  • -

#11 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 27 January 2011 - 11:10 AM

hmmm ok i got the scenario now. fanx aloadx:)
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14417
  • View blog
  • Posts: 57,803
  • Joined: 12-June 08

Re: Error in using DateTime function:((

Posted 27 January 2011 - 11:54 AM

View Postmarileena, on 27 January 2011 - 12:10 PM, said:

hmmm ok i got the scenario now. fanx aloadx:)


What does "fanx aloadx:)" mean?
Was This Post Helpful? 0
  • +
  • -

#13 marileena   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 16
  • Joined: 26-January 11

Re: Error in using DateTime function:((

Posted 29 January 2011 - 09:29 AM

View Postmodi123_1, on 27 January 2011 - 11:54 AM, said:

View Postmarileena, on 27 January 2011 - 12:10 PM, said:

hmmm ok i got the scenario now. fanx aloadx:)


What does "fanx aloadx:)" mean?


fanx alaodx means .... thanks alots or alot:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1