Solved

string to datetime

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
itextsharp with c# 3 35
How we can add Dten600.dll in GAC in c#. 18 55
c#  FTP ftpwebrequest URI invalid 6 47
c# deserialize JSON from web service using JsonConvert 9 61
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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