VB6读取Excel记录

song9999 2008-03-19 08:52:55
VB6能不能不引用Excel和ADO来读取表里的记录?
...全文
403 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2008-03-20
  • 打赏
  • 举报
回复
If Randomize is not called before Rnd, the same series of psuedo-random values will be returned.
不会用函数的话去找找示例代码,我还没看见不用Randomize的rnd示例。
CSG1986 2008-03-20
  • 打赏
  • 举报
回复

灌水机代码:www.dullwolf.cn/CSDNer.rar下载。
蒋晟 2008-03-20
  • 打赏
  • 举报
回复
传个时间给rnd函数做参数吧
song9999 2008-03-20
  • 打赏
  • 举报
回复
.705547511577606 sdf asdf asdf
.705547511577606 qwefrqwe asdf asdf
.705547511577606 qwefrqwe asdf asdf
.705547511577606 qwefrqwe asdf asdf
.705547511577606 qwefrqwe asdf asdf
.705547511577606 qwefrqwe asdf asdf
.705547511577606 1 2 3
我每次查询都是这个结果
我在外面加过Randomize查询结果仍全是.705547511577606这个值
在查询语句内部如何使用Randomize?
song9999 2008-03-20
  • 打赏
  • 举报
回复
我用过Randomize
但返回的值还是同样的,不信你试试
song9999 2008-03-20
  • 打赏
  • 举报
回复
随机数在查询中并非只获取一次,错误
请谅解
song9999 2008-03-20
  • 打赏
  • 举报
回复
我终于明白了随机数在查询中只会获取一次,所以每次查询这一列都是相同的值
我的想法是在这一列中取得不重复的值,如SQL中可以 select Newid(),* from tbstaff
NewID()就可以完成,但这里有什么办法?
song9999 2008-03-19
  • 打赏
  • 举报
回复
Function ReadExcel(ByVal OpenFile As String, Table As String) As String
On Error GoTo ErrExit
Dim DataRec As ADODB.Recordset
Set DataRec = New ADODB.Recordset
DataRec.CursorLocation = adUseClient
DataRec.CursorType = adOpenKeyset
DataRec.LockType = adLockBatchOptimistic
DataRec.Open "SELECT rnd(),* FROM [" & Table & "$]", "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & OpenFile, adOpenStatic, adLockReadOnly, adCmdText
ReadExcel = DataRec.GetString(adClipString, -1, Chr(9), vbCrLf, "")
DataRec.Close
ErrExit:
Set DataRec = Nothing
End Function
为什么rnd()返回的是同一个值?
song9999 2008-03-19
  • 打赏
  • 举报
回复
谢谢大家关注,
请问还有没有更好的办法,因为我做了一个浏览器除了必不可少的MSVBVM60.DLL不希望引用其它控件
vefo 2008-03-19
  • 打赏
  • 举报
回复
用Excel的com组件

jinjazz 2008-03-19
  • 打赏
  • 举报
回复
  Private   Sub   Command27_Click()   
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=D:\ABC.xls;" & "Extended Properties=""Excel 11.0;"""
cn.Open
rs.Open "select * from [sss$] ", cn, adOpenStatic, adLockReadOnly, adCmdText
Do While Not rs.EOF
Debug.Print TypeName(rs.Fields(0).Value) '用TypeName来判断数据类型
Debug.Print TypeName(rs.Fields(1).Value)
rs.MoveNext
Loop
End Sub

7,776

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧