每次运行就弹出"对象打开时,不允许操作"的提示!
添加数据的代码如下:
Private Sub Command3_Click()
Dim txtsql As String
Dim msgtxt As String
Dim conn As ADODB.Connection
Dim mrc As ADODB.Recordset
Dim sql As String
Dim i As Integer
i = 0
While Not List1.Selected(i)
i = i + 1
Wend
txtsql = "select * from PATIENT where Pno='" + Text2.Text + "'"
Set mrc = ExecuteSQL(txtsql, msgtxt)
If mrc.EOF Then
Set conn = New ADODB.Connection
Cs = "FileDSN=his.dsn;UID=sa;PWD=011248;DATABASE=master"
conn.Open Cs
sql = "select * from PATIENT"
mrc.Open "sql", conn, 1, 3
mrc.AddNew
mrc("Pname") = Text1.Text
mrc("Pno") = Text2.Text
mrc("Psex") = List1.List(i)
mrc("Page") = CInt(Text3.Text)
mrc("Phistory1") = Text4.Text
mrc("Phistory2") = Text5.Text
mrc("Phistory3") = Text6.Text
mrc("Phistory4") = Text7.Text
mrc("Phistory5") = Text8.Text
mrc("Pitem1") = Text9.Text
mrc("Pitem2") = Text10.Text
mrc("Pitem3") = Text11.Text
mrc("Pitem4") = Text12.Text
mrc("Pitem5") = Text13.Text
mrc.Update
MsgBox "添加档案记录成功", , "提示"
Pno = Text2.Text
frmchoseddep.Show
Else
If MsgBox("您输入的病人编号已经存在,请去选择档案窗体", vbYesNo, "提示") = vbYes Then
Me.Hide
End If
End If
End Sub
添加数据的代码如下:
Private Sub Command3_Click()
Dim txtsql As String
Dim msgtxt As String
Dim conn As ADODB.Connection
Dim mrc As ADODB.Recordset
Dim sql As String
Dim i As Integer
i = 0
While Not List1.Selected(i)
i = i + 1
Wend
txtsql = "select * from PATIENT where Pno='" + Text2.Text + "'"
Set mrc = ExecuteSQL(txtsql, msgtxt)
If mrc.EOF Then
Set conn = New ADODB.Connection
Cs = "FileDSN=his.dsn;UID=sa;PWD=011248;DATABASE=master"
conn.Open Cs
sql = "select * from PATIENT"
mrc.Open "sql", conn, 1, 3
mrc.AddNew
mrc("Pname") = Text1.Text
mrc("Pno") = Text2.Text
mrc("Psex") = List1.List(i)
mrc("Page") = CInt(Text3.Text)
mrc("Phistory1") = Text4.Text
mrc("Phistory2") = Text5.Text
mrc("Phistory3") = Text6.Text
mrc("Phistory4") = Text7.Text
mrc("Phistory5") = Text8.Text
mrc("Pitem1") = Text9.Text
mrc("Pitem2") = Text10.Text
mrc("Pitem3") = Text11.Text
mrc("Pitem4") = Text12.Text
mrc("Pitem5") = Text13.Text
mrc.Update
MsgBox "添加档案记录成功", , "提示"
Pno = Text2.Text
frmchoseddep.Show
Else
If MsgBox("您输入的病人编号已经存在,请去选择档案窗体", vbYesNo, "提示") = vbYes Then
Me.Hide
End If
End If
End Sub
解决方案 »
- 调用regsvr32能注册一个绝对路径带有中文或带空格的控件吗?
- vb打包问题-为何我的工具条在VB里测试时好好的,但打包安装之后有些功能就不能用了?
- 本人闲的无聊做了一个小软件 可免费下载电影, 欢迎大家过来测试
- listview有一个排序的属性,是否可以不显示排序结果,而只是把排序结果保存到数据库?
- 问 宋体9号字,10号字的高度。
- 请问如何利用程序向web服务器post表单数据???谢谢!!!
- 菜鸟的问题,大家来看看啊,打开调出写入后 如何关闭和保存
- 如何通过API在注册表里修改打印机的PORTNAME。
- datagrid 的小问题
- VB的入门问题
- datacombo操作绑定的adodc的问题。
- VB 全屏播放视频的问题
这个应该是mrc.Open sql, conn, 1, 3 才对吧
set mrc=nothing
set mrc=new ADODB.Recordset
然后再mrc.open
Dim txtsql As String
Dim msgtxt As String
Dim conn As ADODB.Connection
Dim mrc As ADODB.Recordset
Dim sql As String
Dim i As Integer
i = 0
While Not List1.Selected(i)
i = i + 1
Wend
txtsql = "select * from PATIENT where Pno='" + Text2.Text + "'"
Set mrc = ExecuteSQL(txtsql, msgtxt) '干什么用?
If mrc.EOF Then '1
Set conn = New ADODB.Connection
Cs = "FileDSN=his.dsn;UID=sa;PWD=011248;DATABASE=master"
conn.Open Cs
sql = "select * from PATIENT"
mrc.Open "sql", conn, 1, 3 '已经使用又打开,当然不可以
mrc.AddNew
mrc("Pname") = Text1.Text
mrc("Pno") = Text2.Text
mrc("Psex") = List1.List(i)
mrc("Page") = CInt(Text3.Text)
mrc("Phistory1") = Text4.Text
mrc("Phistory2") = Text5.Text
mrc("Phistory3") = Text6.Text
mrc("Phistory4") = Text7.Text
mrc("Phistory5") = Text8.Text
mrc("Pitem1") = Text9.Text
mrc("Pitem2") = Text10.Text
mrc("Pitem3") = Text11.Text
mrc("Pitem4") = Text12.Text
mrc("Pitem5") = Text13.Text
mrc.Update
MsgBox "添加档案记录成功", , "提示"
Pno = Text2.Text
frmchoseddep.Show
Else
If MsgBox("您输入的病人编号已经存在,请去选择档案窗体", vbYesNo, "提示") = vbYes Then
Me.Hide
End If
End If
End Sub
http://download.csdn.net/source/1498324
Set mrc = ExecuteSQL(txtsql, msgtxt)
If mrc.EOF Then
Set conn = New ADODB.Connection
Cs = "FileDSN=his.dsn;UID=sa;PWD=011248;DATABASE=master"
if conn.state=1 then conn.close'加上这一句
conn.Open Cs
sql = "select * from PATIENT"
If mrc.State = 1 Then mrc.Close'加上这一句
mrc.Open "sql", conn, 1, 3
mrc.AddNew
mrc("Pname") = Text1.Text
mrc("Pno") = Text2.Text
mrc("Psex") = List1.List(i)
mrc("Page") = CInt(Text3.Text)
mrc("Phistory1") = Text4.Text
mrc("Phistory2") = Text5.Text
mrc("Phistory3") = Text6.Text
mrc("Phistory4") = Text7.Text
mrc("Phistory5") = Text8.Text
mrc("Pitem1") = Text9.Text
mrc("Pitem2") = Text10.Text
mrc("Pitem3") = Text11.Text
mrc("Pitem4") = Text12.Text
mrc("Pitem5") = Text13.Text
mrc.Update
MsgBox "添加档案记录成功", , "提示"
Pno = Text2.Text
frmchoseddep.Show
Else
If MsgBox("您输入的病人编号已经存在,请去选择档案窗体", vbYesNo, "提示") = vbYes Then
Me.Hide
End If
End If
还有种方法,就是你再定义一个recordset,各是各的,这样就不会发生这样的问题了
2. else中应该有mrc的关闭操作。
3. LZ只不过是要插入一条记录,需要做个动态记录集再更新么?直接一句update就可以了。