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

问题描述

i'm trying to insert data from vb.net form to access data base, i have this code but i have this error:Data type mismatch in criteria expression.

dname: text

dphone: text

idnum: number

dbank: number

dcity: text

rdate: date and time





我是什么尝试过:



Dim conn As New OleDbConnection

Dim sConnString As String

Dim cmd作为新的OleDbCommand

Dim sSQL As String = String.Empty



sConnString =provider = microsoft.ace.oledb.12.0;数据源= | datadirectory | \ delegate_manager.accdb;



conn =新OleDbConnection(sConnString)

conn.Open()

cmd.Connection = conn

cmd.CommandType = CommandType.Text



cmd.CommandText =插入代表( dname,dphone,idnum,dbank,dcity,rdate)VALUES(@ dname,@ dphone,@ idnum,@ dbank,@ dcity,@ rdate)

cmd.Parameters.AddWithValue(@ dname ,TextBox1.Text)

cmd.Parameters.AddWithValue(@ dphone, TextBox2.Text)

cmd.Parameters.AddWithValue(@ idnum,TextBox3.Text)

cmd.Parameters.AddWithValue(@ dbank,TextBox4.Text)

cmd.Parameters.AddWithValue(@ dcity,TextBox5.Text)

cmd.Parameters.AddWithValue(@ rdate,Convert.ToDateTime(DateTimePicker1.Value。日期))

cmd.ExecuteNonQuery()

con.Close()



What I have tried:

Dim conn As New OleDbConnection
Dim sConnString As String
Dim cmd As New OleDbCommand
Dim sSQL As String = String.Empty

sConnString = "provider=microsoft.ace.oledb.12.0; data source = |datadirectory|\delegate_manager.accdb;"

conn = New OleDbConnection(sConnString)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text

cmd.CommandText = "Insert into delegate (dname,dphone,idnum,dbank,dcity,rdate) VALUES(@dname,@dphone,@idnum,@dbank,@dcity,@rdate)"
cmd.Parameters.AddWithValue("@dname", TextBox1.Text)
cmd.Parameters.AddWithValue("@dphone", TextBox2.Text)
cmd.Parameters.AddWithValue("@idnum", TextBox3.Text)
cmd.Parameters.AddWithValue("@dbank", TextBox4.Text)
cmd.Parameters.AddWithValue("@dcity", TextBox5.Text)
cmd.Parameters.AddWithValue("@rdate", Convert.ToDateTime(DateTimePicker1.Value.Date))
cmd.ExecuteNonQuery()
con.Close()

推荐答案


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

08-13 07:51