Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have made a program using vb.net and mysql. But i decided to convert it using access so i can make .exe trial version just in case.

But upon converting i got this error in one specific function

Database
Table Name: Tbl_Attendance
Specific Field Name: F_Date

Objects

Date time picker name: txt_from.Text
Date time picker name: txt_to.Text
Format: yyyy-MM-dd (i.e. 2012-09-05)

I am creating a specific function that once a click a button it will delete records from txt_from.Text to txt_to.Text

This are my codes:

VB
Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click
      If MessageBox.Show("WARNING: Be very careful when deleting records. You cannot undo this procedure!" + vbCrLf + "Do you still want to proceed?", "Attention!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
          open_connection1()
          cmd.CommandText = "delete from tbl_attendance where F_date >= '" & txt_from.Text & "' and F_date <= '" & txt_to.Text & "'"
          cmd.ExecuteNonQuery()
          MessageBox.Show("Time table now is clear from  " + txt_from.Text + " to " + txt_to.Text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
          cn.Close()
      End If
  End Sub


Error: "data type mismatch in criteria expression"

I am very frustrated with this error. please help
Posted
Comments
[no name] 5-Sep-12 11:27am    
"txt_from.Text" is a string not a datetime.
JMAM 5-Sep-12 11:35am    
But the code above works perfectly when u used vb.net and mysql

Try this.

cmd.CommandText = "delete from tbl_attendance where F_date >= #" & Convert.toDatetime(txt_from.Text) & "# and F_date <= #" & Convert.toDatetime(txt_to.Text) & "#"


cmd.CommandText = "delete from tbl_attendance where F_date >= #" & txt_from.Text & "# and F_date <= #" & txt_to.Text & "#"


Dnt use '' for date in ms access only ## will work.

Both will work if not second command will work for sure.(Tested)

Hope This Helps.
 
Share this answer
 
v5
Trying using # for access dates like below

VB
cmd.CommandText = "delete from tbl_attendance where F_date >= '#" & txt_from.Text & "#' and F_date <= '#" & txt_to.Text & "#'"
 
Share this answer
 
Comments
JMAM 5-Sep-12 11:35am    
Thanks for the reply unfortunately it didn't work
BheemG 6-Sep-12 0:34am    
Dnt use both '# for date its wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900