Solved

Date Function in Vb.net

Posted on 2003-11-20
6
343 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
  • 2
6 Comments
 
LVL 4

Expert Comment

by:MajinLoki
Comment Utility
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
Comment Utility

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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now