Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Type Mismatch Error

Question:
I have an SQL statement in my program that looks like this:
data3.recordsource = "SELECT id, date from reservations where (date = '" & maskededit1.text & "') and (id = " & data1.recordset.fields("movie_id").value & ")"
"date" is declared as Date/Time, "id" and "movie_id" are integers. The program crashes on this statement (which is on the line after the SELECT statement):
data3.refresh
It gives me a "Type Mismatch" error. I have spent two days trying to solve this problem.

Answer:
Try the following to replace your code:

Dim sSQL as String

sSQL = "SELECT id, date FROM reservations WHERE "
sSQL = sSQL + "date = " + CVar(MaskedEdit1.Text)
sSQL = sSQL + " AND id = " + data1.recordset("movie_id")
data3.RecordSource = sSQL
data3.Refresh
This broke the SQL statement up to make it more readable. CVar converts text to a Variant, which deals with dates much better. In addition, no parentheses are needed in the SELECT statement. Also, to get the field value, you do not use the Fields collection. The Recordset property is a Dynaset, and can be used as such.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date