如何解决此错误“条件表达式中的数据类型不匹配”。 ? [英] How to resolve this error "data type mismatch in criteria expression." ?

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

问题描述

如果operation =new那么

chargementdb()

cmd =新OleDb.OleDbCommand

cmd.CommandText =插入note1(numprof,nummat,nume,noteDT,typenote,dtenote)值(@ numprof,@ nummat,@ nume,@ noteDT,@ typenote,@ dtenote)

cmd.Connection = cnx

cmd.Parameters.AddWithValue(@ numprof,txtidprof.Text)

cmd.Parameters.AddWithValue(@ nummat,combomatiere.Text)

cmd.Parameters.AddWithValue(@ nume,txtmatricule.Text)

cmd.Parameters.AddWithValue(@ noteDT,txtnote.Text)

cmd。 Parameters.AddWithValue(@ typenote,combotyppenote.Text)

cmd.Parameters.AddWithValue(@ dtenote,txtmatricule.Text)

'MsgBox(DateTimePicker1.Value .Date)

'MsgBox(prof& txtidprof.Text)

'MsgBox(matiere& combomatiere.Text)

'MsgBox(matricule& txtmatricule.Text)

'MsgBox(note& txtnote.Text)

'MsgBox(type note& combotyppenote.Text)

'MsgBox(date& txtmatricule.Text)

cmd.ExecuteNonQuery()



我尝试了什么:



我尝试插入表note1 。

If operation = "new" Then
chargementdb()
cmd = New OleDb.OleDbCommand
cmd.CommandText = "insert into note1(numprof,nummat,nume,noteDT,typenote,dtenote)values(@numprof,@nummat,@nume,@noteDT,@typenote,@dtenote)"
cmd.Connection = cnx
cmd.Parameters.AddWithValue("@numprof", txtidprof.Text)
cmd.Parameters.AddWithValue("@nummat", combomatiere.Text)
cmd.Parameters.AddWithValue("@nume", txtmatricule.Text)
cmd.Parameters.AddWithValue("@noteDT", txtnote.Text)
cmd.Parameters.AddWithValue("@typenote", combotyppenote.Text)
cmd.Parameters.AddWithValue("@dtenote", txtmatricule.Text)
' MsgBox(DateTimePicker1.Value.Date)
'MsgBox("prof " & txtidprof.Text)
'MsgBox("matiere " & combomatiere.Text)
'MsgBox("matricule " & txtmatricule.Text)
'MsgBox("note " & txtnote.Text)
'MsgBox("type note " & combotyppenote.Text)
'MsgBox("date " & txtmatricule.Text)
cmd.ExecuteNonQuery()

What I have tried:

I try to insert into a table note1.

推荐答案

我们无法确定,但最好的猜测是您提供的数据对于您插入的列无效。



你不应该盲目地将字符串传递给SQL,除非将列指定为VARCHAR或NVARCHAR - 如果它是一个数字字段(INT,FLOAT,DECIMAL ...... )或基于日期(DATE,DATETIME,DATETIME2 ...)然后你应该使用适当的TryParse方法将它转换为适当的数据类型,然后再将它发送到SQL:

We can't be sure, but the best guess is that the data you are providing isn't valid for the column you are inserting it into.

You shouldn't just pass strings blindly to SQL, unless the column is specified as VARCHAR or NVARCHAR - if it's a numeric field (INT, FLOAT, DECIMAL ...) or date based (DATE, DATETIME, DATETIME2 ...) then you should use the appropriate TryParse method to convert it to the appropriate datatype before you send it to SQL:
Dim dt As DateTime

If Not DateTime.TryParse(txtmatricule.Text, dt) Then
    ... report problem to user ...
    Return
End If

然后将转换后的值作为参数值传递给SQL。

Then pass the converted value to SQL as the parameter value.


这篇关于如何解决此错误“条件表达式中的数据类型不匹配”。 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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