Solved

string to datetime

Posted on 2012-03-10
4
339 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 50

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 50

Expert Comment

by:Gustav Brock
ID: 37704937
You are welcome!

/gustav
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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