Solved

string to datetime

Posted on 2012-03-10
4
335 Views
Last Modified: 2012-03-10
How to convert String to datetime?
In my IQueryable I have this code.

        public IQueryable<SalesRecord> GetSalesRecordDatimeId(int branchid, string sDate)
        {
            return this.ObjectContext.SalesRecords.Where(so => so.BranchID == branchid && so.TheDate == sDate);

        }

It is error because the TheDate Data Type is set as datetime. I guess I need some converstion about this. How?

My xaml code as follows:
        private void button2_Click(object sender,  RoutedEventArgs e)
        {
            int BrId = int.Parse(this.txtme.Text);
            string Mydate = string.Format(this.datePicker1.Text);
            if (_Context.EntityContainer != null) _Context.EntityContainer.GetEntitySet<SalesRecord>().Clear();
            _Context.Load(_Context.GetSalesRecordDatimeIdQuery(BrId,Mydate));    
        }

Which part of my codes need to change?
0
Comment
Question by:Whing Dela Cruz
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
You could change the string to DateTime:


        public IQueryable<SalesRecord> GetSalesRecordDatimeId(int branchid, DateTime date)
        {
            return this.ObjectContext.SalesRecords.Where(so => so.BranchID == branchid && so.TheDate == date);

        }

It is error because the TheDate Data Type is set as datetime. I guess I need some converstion about this. How?

        private void button2_Click(object sender,  RoutedEventArgs e)
        {
            int BrId = int.Parse(this.txtme.Text);
            DateTime Mydate = DateTime.Parse(this.datePicker1.Text);
            if (_Context.EntityContainer != null) _Context.EntityContainer.GetEntitySet<SalesRecord>().Clear();
            _Context.Load(_Context.GetSalesRecordDatimeIdQuery(BrId,Mydate));    
        }

/gustav
0
 
LVL 14

Expert Comment

by:brendanmeyer
Comment Utility
have a look at http://msdn.microsoft.com/en-us/library/1k1skd40.aspx
there are a few good examples
if you can provide an example of what the Mydate  string is, I may be able to help further
0
 

Author Closing Comment

by:Whing Dela Cruz
Comment Utility
Thanks a lot... More power to you!!!
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
You are welcome!

/gustav
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now