|
-
Jan 10th, 2007, 01:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Data type mismatch
hi all..
I have a program that save Employee data into Access DB
After i save a data and i want to update the data...the error message "Data type mismatch in criteria expression"..will be displayed.
can someone tell me what should i do or change with my coding below.....
badgeno---Numeric
name,grade,project,area,remarks-----Text
doj-------Datetime
camp,monthly(checkboxes)-----text
" update emp set badgeno='" & txtbadgeno.Text & "',name= '" & txtname.Text & "',grade= '" & txtgrade.Text & "', project='" & txtproject.Text & "',area='" & txtarea.Text & "',doj='" & txtdoj.Text & "',camp='" & Check1.Value & "',monthly='" & Check2.Value & "',remarks= '" & txtremarks.Text & "' where badgeno= '" & txtbadgeno.Text & "'"
-
Jan 10th, 2007, 02:12 AM
#2
Addicted Member
Re: Data type mismatch
access database, right? well...
for date/time data fields in access, you have to use
VB Code:
,doj=#" & txtdoj.Text & "#,
using single quotes for date/time data fields are good when using SQL Server 
Additional:::
if the date is coming from a text field... another thing you should do is make sure the text follows the date format in the access database... if it's the Short Date, then do this first before inserting or updating the field in the database:
VB Code:
Format(txtdoj.Text, "mm/dd/yyyy")
Additional Additional:::
leinad is right... for numbers, do not use single quotes(').. it is not necessary, so badgeno can go as he said...
Last edited by dev.rogee; Jan 10th, 2007 at 03:57 AM.
-
Jan 10th, 2007, 03:35 AM
#3
Re: Data type mismatch
can u post the line where you get an error?
-
Jan 10th, 2007, 03:41 AM
#4
Re: Data type mismatch
Don't nest numerics such as badgeno in single quotes.
"set badgeno=" & txtbadgeno.Text & ",name..."
"... where badgeno= " & txtbadgeno.Text
-
Jan 10th, 2007, 07:48 AM
#5
Thread Starter
Addicted Member
Re: Data type mismatch
Thanks for your replies.
I removed single quotes for numeric fields.
When I changed to doj=#" & txtdoj.Text & "# getting an errors "Syntax error in date in query expression ##"
-
Jan 10th, 2007, 10:46 AM
#6
Re: Data type mismatch
Moved to Database forum
What is the value of txtdoj.Text?
And can you show us the fully built SQL string?
(print it to the Immediate window, as shown in this FAQ thread)
-
Jan 10th, 2007, 01:26 PM
#7
Re: Data type mismatch
 Originally Posted by si_the_geek
What is the value of txtdoj.Text?
It looks as if it's null - "Syntax error in date in query expression ##"
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jan 11th, 2007, 06:05 AM
#8
Re: Data type mismatch
yes, I hope the txtdoj.Text is empty. You can do it in this way. Break the query statement like
VB Code:
Sql = "set badgeno=" & txtbadgeno.Text & ",name..."
If Not Trim(txtdoj.Text) = "" Then
Sql = Sql & ", doj=#" & txtdoj.Text & "#"
End If
Sql = Sql & " Where where badgeno= " & txtbadgeno.Text
Hope it helps
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jan 11th, 2007, 04:07 PM
#9
Re: Data type mismatch
VB Code:
Sql = "set badgeno=" & txtbadgeno.Text & ",name..."
If IsDate(Trim(txtdoj.Text)) Then
Sql = Sql & ", doj=#" & txtdoj.Text & "#"
End If
Sql = Sql & " Where where badgeno= " & txtbadgeno.Text
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jan 13th, 2007, 02:06 AM
#10
Thread Starter
Addicted Member
Re: Data type mismatch
Thanks for your replies friends.
I changed my code as follows and it works.Thanks.
Private Sub cmdmodify_Click()
searchcode = Trim(txtbadgeno.Text)
sql = "select * from emp where badgeno= " & searchcode
tmp_rs.Open sql, conn, adOpenDynamic, adLockOptimistic
If tmp_rs.EOF = False Then
tmp_rs("name") = txtname.Text
tmp_rs("grade") = txtgrade.Text
tmp_rs("project") = txtproject.Text
tmp_rs("area") = txtarea.Text
tmp_rs("doj") = txtdoj.Text
...
....
...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|