Solved

string to datetime

Posted on 2012-03-10
4
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

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 51

Expert Comment

by:Gustav Brock
ID: 37704937
You are welcome!

/gustav
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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