回 帖 发 新 帖 刷新版面

主题:关于插入空值问题

Public constr As String = "provider=microsoft.jet.oledb.4.0;  data source=d:\gongzitiao\db1.mdb"
    Public mycon As OleDbConnection = New OleDbConnection(constr)
dim aa as string
aa=""
Dim str1 As String = "insert into luruxinxi(bianhao)values(@ri)"
Dim com1 As OleDbCommand = New OleDbCommand(str1, mycon)
com1.Parameters.Add("@ri", OleDbType.VarChar).Value = aa
如果我让 aa=""
那么运行时就会提示错误信息。出错点就是aa=""如果我把aa付值就没问题了
可是我想让这条记录存入空值.数据库中已经设置此条记录可为空了,
我应该怎么办?
多谢了

回复列表 (共1个回复)

沙发

Public mycon As OleDbConnection = New OleDbConnection(constr)
dim aa as string
aa=""
Dim str1 As String = "insert into luruxinxi(bianhao)values(@ri)"
Dim com1 As OleDbCommand = New OleDbCommand(str1, mycon)
com1.Parameters.Add("@ri", OleDbType.VarChar).Value = aa

这些代码改成:
Public mycon As OleDbConnection = New OleDbConnection(constr)
dim aa as string
Dim str1 As String = "insert into luruxinxi(bianhao)values('')"
Dim com1 As OleDbCommand = New OleDbCommand(str1, mycon)

直接把空值放进去看看行不;
或者
你尝试一下: aa=Null
看看可不可以。。

我来回复

您尚未登录,请登录后再回复。点此登录或注册