标题:vb 通过 adodc 和 datagrid 实现数据表的导入后,datagrid 不能显示数据。
只看楼主
wangzhongda
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2014-11-10
结帖率:100%
 问题点数:0 回复次数:0 
vb 通过 adodc 和 datagrid 实现数据表的导入后,datagrid 不能显示数据。
错误出现在,me.adodc1.refresh,错误提示“[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序”
程序代码:
Dim str As String

Private Sub Command1_Click()

Me.CommonDialog1.ShowOpen
str = Me.CommonDialog1.FileName
Text1.Text = str
End Sub

Private Sub Command2_Click()

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
right1 = Right(str, 3)
If LCase(right1) <> "dbf" Then
MsgBox "不能识别该文件,请选择正确的表进行导入"
Else
cn.ConnectionString = "Provider=msdasql;DRIVER=microsoft visual foxpro driver;uid=;deleted=yes;null=no;backgroundfetch=no;exclusive=no;sourcetype=dbf;sourcedb=" & str & ""
cn.Open
sql = "select * from'" & str & "'"
Set rs = cn.Execute(sql)
cn.Close
Set cn1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset

cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\ddc\file.mdb;Persist Security Info=False"
sql1 = "select* from student"
rs1.Open sql1, cn1, 3, 2
cn.Open
rs.Open sql, cn, 1, 1
Do While rs.EOF <> True

 rs1.AddNew

 rs1!sno = rs!sno

 rs1!sname = rs!sname

 rs1!ssex = rs!ssex

 rs1!sage = rs!sage

 rs1!sdept = rs!sdept

 rs1.Update

 rs.MoveNext

 Loop

 MsgBox "导入成功"

 End If

 cn.Close

 Me.Adodc1.Refresh

 Me.DataGrid1.Refresh
End Sub


[ 本帖最后由 wangzhongda 于 2014-11-13 15:46 编辑 ]
搜索更多相关主题的帖子: 数据表 数据源 
2014-11-13 15:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-438526-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.485115 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved