为什么提示保存成功,在数据库中却没有数据?乖乖的!
我不通过DSN直接访问SQL,连接字符串如下:
Public CNN
Public RST
Sub mydovro()
Set CNN = CreateObject( "ADODB.Connection ")
Set RST = CreateObject( "ADODB.Recordset ")
CNN.Open "DRIVER=SQL Server;SERVER=WWW-45DDBAA9B9D;UID=sa;PWD=;DATABASE=sales "
End Sub
然后我在增加数据时用如下语句:
Private Sub CommandButton1_Click() '新增数据
On Error Resume Next
If TextBox1 = " " Or TextBox2 = " " Or ComboBox1 = " " Then
MsgBox "输入数据不完整,请核对后录入! ", vbInformation, "DOVRO ": Exit Sub
Else
If MsgBox( "是否确认新增数据? ", vbYesNo + vbQuestion, "DOVRO ") = vbNo Then Exit Sub
Call 输入
End If
Call 查询
MsgBox "单据新增完毕! ", vbInformation, "DOVRO "
End Sub
Sub 输入()
Call mydovro
If Not RST.EOF Then RST.MoveLast
With RST
SQL = "insert into frmhy(hybh,hyname,hyshop,hymob) "
SQL = SQL & " values( ' " & TextBox1.Text & " ', "
SQL = SQL & " ' " & TextBox2.Text & " ', "
SQL = SQL & " ' " & ComboBox1.Text & " ', "
SQL = SQL & " ' " & IIf(TextBox3.Text = " ", Null, TextBox3.Text) & " ' "
CNN.Execute SQL
End With
RST.Close: CNN.Close
End Sub
可是在点击保存后,保存成功的提示也出现了,可是在数据库里竟然没有数据,怎么回事?
[解决办法]
跟踪看看到底insert 代码执行没
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
最新版本:20070212
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
[解决办法]
楼上说的有理,问题多数是出在这里滴
[解决办法]
问题就在On Error Resume Next
去掉试试
[解决办法]
SQL = SQL & " ' " & IIf(TextBox3.Text = " ", Null, TextBox3.Text) & " ' "
这里如果TextBox3.Text = " ",插入的是 'null '这个值而不是空值
而且,最后少一个 ") "
[解决办法]
SQL = SQL & " ' " & IIf(TextBox3.Text = " ", Null, TextBox3.Text) & " ' "
换成
SQL = SQL & " " & IIf(TextBox3.Text = " ", "Null ", " ' " & TextBox3.Text & " ' ") & ") "
试试
[解决办法]
把 输入 改动一下:
function 输入() as boolean
输入=true
Call mydovro
If Not RST.EOF Then RST.MoveLast
With RST
SQL = "insert into frmhy(hybh,hyname,hyshop,hymob) "
SQL = SQL & " values( ' " & TextBox1.Text & " ', "
SQL = SQL & " ' " & TextBox2.Text & " ', "
SQL = SQL & " ' " & ComboBox1.Text & " ', "
SQL = SQL & " ' " & IIf(TextBox3.Text = " ", Null, TextBox3.Text) & " ' "
CNN.Execute SQL
End With
RST.Close: CNN.Close
exit function
Err:
输入=false
End function
[解决办法]
该字段不容许空值, 修改表结构