条件表达式中的数据类型不匹配。 MS Access VB [英] Data type mismatch in criteria expression. MS Access VB

查看:51
本文介绍了条件表达式中的数据类型不匹配。 MS Access VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

' OK button
   Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
       Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\Jill\Desktop\saddbase\Sadsystem\Sadsystem\bin\Debug\tenant.mdb")
       Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM info WHERE TN_ID = '" & UsernameTextBox.Text & "' AND Password = '" & PasswordTextBox.Text & "' ", con)
       con.Open()
       Dim sdr As OleDbDataReader = cmd.ExecuteReader()
       ' If the record can be queried, Pass verification and open another form.
       If (sdr.Read() = True) Then
           MessageBox.Show("The user is valid!")

           Me.Hide()
       Else
           MessageBox.Show("Invalid Tenant ID or password!")
       End If





当我运行程序时,cmd.ExecuteReader()中出现错误。 *标准表达式中的数据类型不匹配*请帮助如何解决此错误。



When I run the program there's an error in cmd.ExecuteReader(). *Data type mismatch in criteria expression* please help how to fix this error.

推荐答案

我猜你的用户名列并没有真正命名为TN_ID,但更接近于用户名。 TN_ID列可能是您的主键,您尝试使用相等性将其与文本值进行比较,文本值是数据类型不匹配。
I'm guessing your username column is not really named TN_ID, but something closer to Username. The TN_ID column is probably your primary key and you are trying to use equality to compare it with a text value, which is a data type mismatch.


TN_ID可以是数字字段(可能是ID罗恩建议的场地)。检查数据库中的数据类型。如果它是数字字段,那么当您将字符串值UsernameTextBox.Text传递给它时,错误是有意义的。



如果TN_ID是用户名字段,那么

Integer.Parse(UsernameTextBox.Text)会这样做,前提是用户名是数字的组合,也改变它是用户ID更有意义。



否则如果TN_ID不是用户名字段那么

将TN_ID更改为右字段name(请记住数据类型转换)。



否则,如果TN_ID应该包含用户名,而用户名又包含字母,则将TN_ID字段转换为varchar(如果是数字)。
TN_ID could be a numeric field (possibly ID field as Ron suggested). Check for it's datatype in the database. If it is numeric field then the error makes sense as you are passing string value "UsernameTextBox.Text" into it.

If TN_ID is the username field then
"Integer.Parse(UsernameTextBox.Text)" would do, provided username is combination of numbers, also change it is userid to make more sense.

else if TN_ID is not the username field then
change the TN_ID to right field name (keep in mind the datatype conversion).

else, if TN_ID should hold username which in turns contains alphabets, convert the TN_ID field to varchar (if numeric).


什么是tn_id和密码的数据类型我不知道

请检查数据类型

如果TN_ID是整数且密码是字符串然后尝试

(SELECT * FROM info WHERE TN_ID =&UsernameTextBox.Text&AND Password ='&PasswordTextBox.Text&',con)



如果TN_ID是字符串而密码是字符串则尝试这个

(SELECT * FROM info WHERE TN_ID ='&UsernameTextBox.Text&'AND Password ='&PasswordTextBox.Text& ',con)
what is the data type of the tn_id and password i don't know
please check the datatypes
If TN_ID is integer and password is string then try
("SELECT * FROM info WHERE TN_ID = " & UsernameTextBox.Text & " AND Password = '" & PasswordTextBox.Text & "' ", con)

if TN_ID is string and password is string then try this
("SELECT * FROM info WHERE TN_ID = '" & UsernameTextBox.Text & "' AND Password = '" & PasswordTextBox.Text & "' ", con)


这篇关于条件表达式中的数据类型不匹配。 MS Access VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆