?
Solved

Date Function in Vb.net

Posted on 2003-11-20
6
Medium Priority
?
352 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 80 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

764 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