VB6读取EXCEL里全部数据问题

kennyjapan 2008-11-13 10:12:59
VB6读取EXCEL里全部数据时候
如果有二条数据相同的话用什么方法去判断.
程序代码如下:
Private Sub cmdOut_Click()  
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlCells As Excel.Range
Dim i As Integer
Dim OraDyn As OraDynaset
Dim OraDyn1 As OraDynaset
Dim strSql As String
Dim strSql1 As String
Dim intR As Integer
Dim intC As Integer
Dim err As String
Dim err1 As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(mstrDataFile)
Set xlSheet = xlBook.ActiveSheet
Set xlCells = xlSheet.Cells
intR = xlSheet.Cells.SpecialCells(xlCellTypeLastCell).Row - 4
intC = 4
ReDim myText(1 To intR, 1 To intC)
For i = 1 To intR
myText(i, 1) = CStr(xlCells(i + 4, 2).Value)
myText(i, 2) = CStr(xlCells(i + 4, 3).Value)
myText(i, 3) = CStr(xlCells(i + 4, 5).Value)
myText(i, 4) = CStr(xlCells(i + 4, 6).Value)
strSql = "SELECT "
strSql = strSql & " HACHUTEN, "
strSql = strSql & " TEKIZAISU "
strSql = strSql & " FROM "
strSql = strSql & " TMJ0BA "
strSql = strSql & " WHERE "
strSql = strSql & " SOUKOCD = '" & xlCells(i + 4, 2).Value & "' "
strSql = strSql & " AND HINCD ='" & xlCells(i + 4, 3).Value & "' "
Set OraDyn = OraDB.CreateDynaset(strSql, ORADYN_READONLY)
If myText(i, 1) > 5 Then
err = "倉庫CD:1,2,3,4,5以外不可。"
End If
If IsNumericCheck(xlCells(i + 4, 3)) = True Then
err1 = "商品CD:半角英数。"
End If
If OraDyn.EOF = True Then
xlCells(i + 4, 7) = err & err1 & "在庫残高。"
Else
strSql1 = " UPDATE TMJ0BA SET "
strSql1 = strSql1 & " ZASOSHIKI = ' * ' ,"
strSql1 = strSql1 & " HACHUTEN = '" & xlCells(i + 4, 5).Value & "' ,"
strSql1 = strSql1 & " TEKIZAISU = '" & xlCells(i + 4, 6).Value & "' ,"
strSql1 = strSql1 & " LOTNO = ' * ' "
strSql1 = strSql1 & " WHERE "
strSql1 = strSql1 & " SOUKOCD = '" & xlCells(i + 4, 2).Value & "' "
strSql1 = strSql1 & " AND HINCD ='" & xlCells(i + 4, 3).Value & "' "
OraDB.ExecuteSQL (strSql1)
End If
Next i
Set xlCells = Nothing
Set xlSheet = Nothing
xlBook.Save
xlBook.Close
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub
...全文
359 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lkclover 2008-11-19
  • 打赏
  • 举报
回复
先排序下 然后只要判断当前条和上一条是否相同
Amy_Dream 2008-11-13
  • 打赏
  • 举报
回复
将你的Excel作为vb程序的数据库!
jhone99 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kennyjapan 的回复:]
引用 1 楼 of123 的回复:

把 Excel 作为外部数据库,用数据库对象直接对 Sheet 进行查询。找到相同记录很容易。


可以告诉我.我的程序在什么地方改呢
[/Quote]

完全是另外一种方式
kennyjapan 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 of123 的回复:]

把 Excel 作为外部数据库,用数据库对象直接对 Sheet 进行查询。找到相同记录很容易。

[/Quote]
可以告诉我.我的程序在什么地方改呢
of123 2008-11-13
  • 打赏
  • 举报
回复

把 Excel 作为外部数据库,用数据库对象直接对 Sheet 进行查询。找到相同记录很容易。
kennyjapan 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Amy_Dream 的回复:]
将你的Excel作为vb程序的数据库!
[/Quote]
数据可以取得到呀,如果有二条数据一样的情况下,程序就终了.这样的判断不会做呀.

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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