您看看哪错了,谢谢
呵呵,您别笑话,自学,还是第一次。
我现在做了两个界面,一个主界面,代码如下:
----------------------
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
----------------------
Private Sub book_in_Click()
frmbookin.Show
End Sub
Public Sub Form_Load()
conn.ConnectionString = "Driver={sql server};server=wxfjx;uid=sa;pwd=;database=book "
conn.Open
'连接数据库
frmMain.Caption = "图书馆管理系统 "
frmMain.Top = (Screen.Height - frmMain.Height) / 2
frmMain.Left = (Screen.Width - frmMain.Width) / 2 '窗口居中
End Sub
---------------------
然后又做了一个界面,按钮点击进去
代码如下:
------------------------------
Private Sub cmd_exit_Click()
Unload Me
End Sub
--------------------------------
Private Sub cmd_save_Click()
Dim rs As New ADODB.Recordset
Dim sql As String
If ((Text_isbn.Text = " ") And (Text_bname.Text = " ") And (Text_author.Text = " ") And (Text_total.Text = " ")) Then
Beep
MsgBox " 请将各项数据填写完整! ", 48, "警告! "
Else
sql = "select * from book where isbn= ' " & Text_isbn.Text & " ' "
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs.EOF Then
rs.AddNew
rs.Fields(0) = Trim(Text_isbn.Text)
rs.Fields(1) = Trim(Text_bname.Text)
rs.Fields(2) = Trim(Text_author.Text)
rs.Fields(3) = 0
rs.Fields(4) = Trim(Text_price.Text)
rs.Fields(5) = Trim(Text_total.Text)
rs.Update
MsgBox "0000000 "
rs.Close
End If
End If
End Sub
------------------------
Private Sub Form_Load()
frmbookin.Top = (Screen.Height - frmbookin.Height) / 2
frmbookin.Left = (Screen.Width - frmbookin.Width) / 2
Label_isbn.Caption = "国际标准编号: "
Label_bname.Caption = "书名: "
Label_author.Caption = "作者: "
Label_price.Caption = "价格: "
Label_total.Caption = "总数: "
Text_isbn.Text = " "
Text_bname.Text = " "
Text_author.Text = " "
Text_price.Text = " "
Text_total.Text = " "
cmd_save.Caption = "保存 "
cmd_cancle.Caption = "取消 "
cmd_exit.Caption = "退出 "
Frame1.Caption = "图书信息 "
Frame2.Caption = "图书列表 "
End Sub
运行后提示:实时错误3001 参数类型不正确 或不在可以接受的范围之内,或与其他参数冲突。
然后 rs.Open sql, conn, adOpenKeyset, adLockPessimistic 提示出来
谢谢了!!
[解决办法]
可能conn不是全局的吧
导致rs.Open sql, conn, adOpenKeyset, adLockPessimistic丢失参数
[解决办法]
添加一个 module,然后public conn as ..
[解决办法]
1)看看你book表中的 isbn=字段类型,若为自动编号或int 类型应该写
select * from book where isbn= " & Text_isbn.Text & " 没有单耳朵
2)
rs.AddNew
rs.Fields(0) = Trim(Text_isbn.Text) ' ' '若在表中此字段是自动编号则不能给其赋值
/////也就是说 这句应该不写 而直接写
rs.AddNew
rs.Fields(1) = Trim(Text_bname.Text)
rs.Fields(2) = Trim(Text_author.Text)
.....
3)另外想给你指出一个问题,就是你在做新加操作为什么要查询select * from book where isbn= " & Text_isbn.Text & " ??
你可以直接写 select * from book 或者是 select * from book where isbn isnot null
在更改的时候才需要带条件
[解决办法]
新建一个模块
把Dim conn As New ADODB.Connection
移到模块中
Global conn As New ADODB.Connection
参考一下!