我试图在flexgrid中显示所有记录。 [英] I am trying to display all records in a flexgrid.
本文介绍了我试图在flexgrid中显示所有记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次按下命令按钮,错误424对象需要出现
公共 con1 作为 新 ADODB.Connection
公开 rs 作为 新 ADODB.Recordset
Dim q1 As String
Dim i 作为 整数
公共 Sub con()
con1.ConnectionString = Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\ TrainTimeSchedule.accdb
设置 con1 = 新 ADODB.Connection
con1.Open( dsn123)
结束 Sub
公共 Sub opentable(sql As 字符串)
设置 rs = con1.Execute(sql)
结束 Sub
私有 Sub Command1_Click()
q1 = 选择TrainID,TrainName,Source,来自TrainTable的目的地,车站,DayOfWeek,其中Source ='& tex1.Text& '& 和Destination ='& Text2.Text& ')
opentable(q1)
MSFlexGrid1.DataSource = rs
结束 Sub
解决方案
您好请使用以下代码解决您的问题:
公开 adodbcon 作为 新 ADODB.Connection
公共 adodbrs 作为 新 ADODB.Recordset
公共 Sub opentable(sql As 字符串)
adodbcon .ConnectionString = Provider = Microsoft.Jet.OLEDB.4.0;数据源= E:\ TrainT imeSchedule.accdb
设置 adodbcon = 新 ADODB.Connection
adodbcon.Open( dsn123)
设置 adodbrs = adodbcon .Execute(sql)
结束 Sub
私有 Sub Command1_Click()
Dim q1 as String
q1 = < span class =code-string> 从TrainTable中选择TrainID,TrainName,Source,Destination,Stations,DayOfWeek,其中Source = N'& tex1.Text& '& 和Destination = N'& Text2.Text& ')
opentable(q1)
MSFlexGrid1.DataSource = rs
结束 Sub
最后记住你应该调用adodbcon.Close()来关闭adodb连接,因为adodb是连接基础,如果你不这样做,下次使用adodb.Open()就会出错。
Everytime I press the command button , "error 424 Object required" is showing up
Public con1 As New ADODB.Connection
Public rs As New ADODB.Recordset
Dim q1 As String
Dim i As Integer
Public Sub con()
con1.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\TrainTimeSchedule.accdb"
Set con1 = New ADODB.Connection
con1.Open ("dsn123")
End Sub
Public Sub opentable(sql As String)
Set rs = con1.Execute(sql)
End Sub
Private Sub Command1_Click()
q1 = "Select TrainID,TrainName,Source,Destination,Stations,DayOfWeek from TrainTable Where Source ='" & tex1.Text & "'" & "and Destination = '" & Text2.Text & "')"
opentable (q1)
MSFlexGrid1.DataSource = rs
End Sub
解决方案
Hi Please use follow of code for solve your problem:
Public adodbcon As New ADODB.Connection Public adodbrs As New ADODB.Recordset Public Sub opentable(sql As String) adodbcon .ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\TrainTimeSchedule.accdb" Set adodbcon = New ADODB.Connection adodbcon.Open ("dsn123") Set adodbrs = adodbcon .Execute(sql) End Sub Private Sub Command1_Click() Dim q1 as String q1 = "Select TrainID,TrainName,Source,Destination,Stations,DayOfWeek from TrainTable Where Source =N'" & tex1.Text & "'" & "and Destination =N'" & Text2.Text & "')" opentable(q1) MSFlexGrid1.DataSource = rs End Sub
Remember finally your should call adodbcon.Close() for closing adodb connection because adodb is connection base and if you don`t do it you will get error at the next using as adodb.Open().
这篇关于我试图在flexgrid中显示所有记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文