当我只调用下面的代码一次的时候,没有问题,
两次以上就出现问题了,
实时错误 '3705'
对象打开时,不允许操作
我就不知道,如何显示数据后关闭数据源,头疼啊
请大侠指点,谢谢先!代码如下:
Public g_connFast As New ADODB.Connection
Public g_rsFast As New ADODB.Recordset Public Function Getdata(sqlcode As String)
dim sqlfromdata as string
sqlfromdata = "select * from DATA where pro_ID like '%" & sqlcode & "%'"
g_connFast.CursorLocation = adUseClient
g_connFast.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& dbaddress & ";Persist Security Info=False;"
g_connFast.Open
g_rsFast.Open sqlfromdata, g_connFast, adOpenStatic, adLockReadOnly
Set frmFirst.DataGrid1.DataSource = g_rsFast End Function
解决方案 »
- 菜鸟问题 帮帮忙 谢谢了
- 求助: 关于mscomctl.ocx与用户权限的问题
- 中文字段排序
- 怎么用outlook发邮件?
- 如何在程序中更改系统日期格式?
- 用ADO对数据库进行修改和删除操作!!!
- vb odbc连接access数据库
- 靠,这下可怎么办,以前我感兴趣的贴子,我都要up,现在怎么找不到了,我还没来得及down
- 用VB抓图
- 虚心求教:使用ADO连远程数据库。
- 谁知道 怎样在windows 背景也就是screen上画图?
- 需要打印预览的朋友们,请过来看看,用我的打印预览控件可以轻松搞定,而且很简单、截面也完全个性化,并且是微软office风格,可以根据客户要求定制控件.可以打印条形码、支票。
记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象
Private Sub Command1_Click()
'strsql 是你的查询语句 你可以order by 排序的字段
'strsql="select xh as 学号 from 表" 这里的学号就是你datagrid中列的标题 strsql="select 字段 from 表"
Set Db = New Connection
Db.CursorLocation = adUseClient
'下面的连接数据字符串你要修改一下
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = adoPrimaryRS
end sub
Dim sqlfromdata As String
sqlfromdata = "select * from DATA where pro_ID like '%" & sqlcode & "%'"
g_connFast.CursorLocation = adUseClient
g_connFast.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbaddress & ";Persist Security Info=False;"
If g_connFast.state = adstateopen Then
g_connFast.Close
g_connFast.Open
End If
If g_rsFast.state = adstateopen Then g_rsFast.Close
g_rsFast.Open sqlfromdata, g_connFast, adOpenStatic, adLockReadOnly
Set frmFirst.DataGrid1.DataSource = g_rsFastEnd Function
你的方法调试没有通过,
不过修改了一下就可以了,谢谢~~~~顺便再问个问题哦,呵呵1.什么查询语句可以直接查出 列的名称 啊,就是 列的标题,
2.从主界面(使用了datagrid控件,而且显示了数据)中调出 子界面(使用了me.hide frmInfoAdd.show 语句),在这个子界面中填写信息,然后我点击“添加信息”按钮,确认已经把数据加入了数据库;接着,点击“返回”按钮(unload me frmMain.show );可是datagrid控件不能显示我刚刚添加的信息。不知道如何解决。请教高手~~~~
谢谢~~~
Public Function Getdata(sqlcode As String)
Dim sqlfromdata As String If g_connFast.State = adStateOpen Then g_connFast.Close
If g_rsFast.State = adStateOpen Then g_rsFast.Close sqlfromdata = "select * from DATA where pro_ID like '%" & sqlcode & "%'"
g_connFast.CursorLocation = adUseClient
g_connFast.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbaddress & ";Persist Security Info=False;"
g_rsFast.Open sqlfromdata, g_connFast, adOpenStatic, adLockReadOnly
Set frmFirst.DataGrid1.DataSource = g_rsFastEnd Function
在datagrid控件中,鼠标选定了5行记录,
可不可以将这5行记录中数据输出到EXCLE 或WORD?
有代码可以参考么?谢谢下面代码中,好像只可以插入字符输出,怎么使用变量输出就不懂了,请高手指点。 Dim Wapp As Object '定义变量Wapp为Word对象
Dim sqltemp As String
Set Wapp = CreateObject("Word.application") '设置变量Wapp为Word对象
'Wapp.Visible = True
Wapp.Documents.Add '打开一个Word空文档
Wapp.Selection.InsertAfter ("fdfds") '插字符串
Wapp.ActiveDocument.SaveAs ("e:\hello2") '存盘
Wapp.ActiveDocument.Close '关闭Word文件
Wapp.Quit '退出Word
Set Wapp = Nothing '释放内存
====================================================
g_connFast(0).Name '得到第1列标题
g_connFast(1).Name '得到第2列标题
-------------------------------------------------
代码中缺少打开数据库连接语句:
......
g_connFast.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbaddress & ";Persist Security Info=False;"
g_connFast.Open '<----------------------缺少这句
g_rsFast.Open sqlfromdata, g_connFast, adOpenStatic, adLockReadOnly
......
--------------------------------------------
' Wapp.Selection.InsertAfter ("fdfds") '直接插字符串dim str as string
str="fdfds"
Wapp.Selection.InsertAfter str '使用变量来完成插字符串
-------------------------------------------数据库的连接我用代码在主界面中Form_Load()调用的,
不知道怎么刷新datagrid控件中的数据哦,在子界面中可以用Form_Unload来完成么?
---------------------------------------------------------------------
你写的 Getdata()过程就是刷新DataGrid了,你在子界面添加了数据(数据库已经更新),需要重新查询数据,以便更新DataGrid的显示,所以,你在子界面的窗体Unload事件里调用主界面的Getdata()过程就行了Private Sub Form_Unload()
主界面.Getdata (参数)
End Sub