Solved

Date Function in Vb.net

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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