Solved

string to datetime

Posted on 2012-03-10
4
336 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
ID: 37704810
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
ID: 37704812
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
ID: 37704849
Thanks a lot... More power to you!!!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37704937
You are welcome!

/gustav
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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