Solved

Date Function in Vb.net

Posted on 2003-11-20
6
350 Views
Last Modified: 2010-05-01
I want to bring data from MS Access where date Column >= some date

I m writing this code in VB.net



thisquery = "select * from TABLE where DTCOLUMN >= '" & CDate(newdate) & "'"

The access table has a Coulmn DTCOLUMN of type date/time

Its giving me an error..
Data type mismatch

Please let me know .
Thanks
0
Comment
Question by:tjpj
[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
6 Comments
 
LVL 4

Expert Comment

by:MajinLoki
ID: 9790379
you need to use a datetime object

then, in your sql, you can parse in a date

thisquery = "select * from TABLE where DTCOLUMN >= '" & DateTime.Parse("date_as_string") & "'"
0
 

Author Comment

by:tjpj
ID: 9790590

Now
Its giving me the following error :

The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
0
 
LVL 4

Accepted Solution

by:
MajinLoki earned 20 total points
ID: 9791329
I did a couple tests.  

at the top, I have
Imports sql = System.Data.SqlClient


Dim connect As sql.SqlConnection
        Dim cm As sql.SqlCommand
        Dim temp As String, test As Integer

        connect = Manager.getconnect() 'this is my own method which returns a connection to the database
        connect.Open()

        'sent is a datetime field in my database

        temp = "select count(*) from table where sent >= '4/4/2003'"
        cm = New sql.SqlCommand(temp, connect)
        test = cm.ExecuteScalar()
        MsgBox(test)

        temp = "select count(*) from table where sent >= '" & DateTime.Parse("4/4/2003") & "'"
        cm.CommandText = temp

        test = cm.ExecuteScalar()

        MsgBox(test)

Both statements execute and both statements return the same value from my database.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 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