Solved

Date Function in Vb.net

Posted on 2003-11-20
6
347 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

813 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

9 Experts available now in Live!

Get 1:1 Help Now