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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date