vb中连接无法用于执行此操作。在此上下文中它可能已被关闭或无效
代码如下OptionExplicitPrivateSubCommand1_Click()Dimrs_bookkindAsNewADODB.RecordsetDimsqlA...
代码如下
Option Explicit
Private Sub Command1_Click()
Dim rs_bookkind As New ADODB.Recordset
Dim sql As String
If Trim(Text1.Text) = "" Then
MsgBox "图书类别名称不能为空!", 16, "类别名称错误"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "图书类别编号不能为空!", 16, "类别编号错误"
Text2.SetFocus
Exit Sub
End If
sql = "select * from 图书类别 where 类别名称="
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_bookkind.EOF Then
rs_bookkind.AddNew
rs_bookkind.Fields(0) = Trim(Text1.Text)
rs_bookkind.Fields(1) = Trim(Text2.Text)
rs_bookkind.Update
MsgBox "添加图书类别成功!", 16, "图书类别错误"
rs_bookkind.Close
Else
MsgBox "图书类别重复!", 16, "图书类别错误"
Text1.SetFocus
Text1.Text = ""
rs_bookkind.Close
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
出错语句是
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic 展开
Option Explicit
Private Sub Command1_Click()
Dim rs_bookkind As New ADODB.Recordset
Dim sql As String
If Trim(Text1.Text) = "" Then
MsgBox "图书类别名称不能为空!", 16, "类别名称错误"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "图书类别编号不能为空!", 16, "类别编号错误"
Text2.SetFocus
Exit Sub
End If
sql = "select * from 图书类别 where 类别名称="
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_bookkind.EOF Then
rs_bookkind.AddNew
rs_bookkind.Fields(0) = Trim(Text1.Text)
rs_bookkind.Fields(1) = Trim(Text2.Text)
rs_bookkind.Update
MsgBox "添加图书类别成功!", 16, "图书类别错误"
rs_bookkind.Close
Else
MsgBox "图书类别重复!", 16, "图书类别错误"
Text1.SetFocus
Text1.Text = ""
rs_bookkind.Close
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
出错语句是
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic 展开
1个回答
展开全部
sql = "select * from 图书类别 where 类别名称='" & Text1.Text & "'" ' 这少添加文本框
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic 'conn对象在这里没见,要确保打开了
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic 'conn对象在这里没见,要确保打开了
更多追问追答
追问
那应该怎么改?
追答
Const cntString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=StockLibaray;"
dim conn As new Connection
conn.Open cntString
'这部分打开连接对象,不过是连接SqlServer数据库,根据数据库类型连接串不同的,你可以通过ado控件与数据库建立连接,然后把连接串拷贝过来
sql = "select * from 图书类别 where 类别名称='" & Text1.Text & "'"
rs_bookkind.Open sql, conn, adOpenKeyset, adLockOptimistic
'conn处的参数可以是连接对像也可以是连接串。
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询