Foxtable(狐表)用户栏目专家坐堂 → 高手帮忙排下错,谢谢


  共有7745人关注过本帖树形打印复制链接

主题:高手帮忙排下错,谢谢

帅哥哟,离线,有人找我吗?
cxqxjyzg
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:64 积分:610 威望:0 精华:0 注册:2012/3/14 8:46:00
高手帮忙排下错,谢谢  发帖心情 Post By:2012/5/4 10:59:00 [只看该作者]

下面的代码,我的目的是:从一个文本文件读入我需要的数据加载到WeatherData表里面,在加数据的时候先判断某日数据是否存在,如果存在,则替换相应数据,如果不存在,说明这个日期(这个日期不允许重复)没有数据,新增一行,再加载数据。

现在能加数据了,问题是如果多次加入数据会多出空行来,这个空行是那里产生的,请帮忙排查下,我看了N遍也找不到原因,谢谢!!

 

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.InitialDirectory ="E:\A0File\"
dlg.Filter= "所有文件|*.*" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Dim S As String = FileSys.ReadAllText(dlg.FileName)
Dim mmID As String =s.SubString(0,5)
output.show (mmID)
Dim mmDate As Date
Dim dr As DataRow
Dim mmYM As String =s.SubString(28,4) & "-" & s.SubString(33,2) & "-"
Dim ss As String
ss=s.Remove(0,s.LastIndexOf("T0")+3)
ss=ss.Remove(ss.IndexOf("="))
Dim s2() As String =ss.Split(chr(13))
OutPut.show(s2.Length)
For i As Integer =0 To s2.Length-1
    'OutPut.show(i & "=" &s2(i))
    Dim s3() As String =s2(i).Split(" ")
    mmDate =Cdate(mmYM & (i+1))
    'output.show(mmDate)
    Dim rr As String = "mID = '" & mmID & "' And mDate = " & "#" & mmDate & "#"
    'output.show(rr)
    dr = DataTables("WeatherData").Find(rr)
    If dr IsNot Nothing  Then
        Dim r As Integer
        r = Tables("WeatherData").FindRow(rr, 0, True )
        If r >= 0 Then '如果找到的话
            Tables("WeatherData").Position = r '定位到找到的行.
        End If

        'output.show("找到:" & Tables("WeatherData").Position)
        Tables("WeatherData").Current("mT02")=s3(0)
        Tables("WeatherData").Current("mT08")=s3(1)
        Tables("WeatherData").Current("mT14")=s3(2)
        Tables("WeatherData").Current("mT20")=s3(3)
        Tables("WeatherData").Current("mGt")=s3(4)
        Tables("WeatherData").Current("mDt")=s3(5)
       
    Else
        DataTables("WeatherData").AddNew()
        Tables("WeatherData").Position=Tables("WeatherData").Position+1
        Tables("WeatherData").Current("mID")=mmID
        Tables("WeatherData").Current("mDate")=mmDate
        Tables("WeatherData").Current("mT02")=s3(0)
        Tables("WeatherData").Current("mT08")=s3(1)
        Tables("WeatherData").Current("mT14")=s3(2)
        Tables("WeatherData").Current("mT20")=s3(3)
        Tables("WeatherData").Current("mGt")=s3(4)
        Tables("WeatherData").Current("mDt")=s3(5)
       
    End If
Next
    Else
    MessageBox.Show("你未选择任何文件" ,"提示") '提示用户选择的文件
End If


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2012/5/4 13:02:00 [只看该作者]

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.InitialDirectory ="E:\A0File\"
dlg.Filter= "所有文件|*.*" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
    Dim S As String = FileSys.ReadAllText(dlg.FileName)
    Dim mmID As String =s.SubString(0,5)
    output.show (mmID)
    Dim mmDate As Date
    Dim dr As DataRow
    Dim mmYM As String =s.SubString(28,4) & "-" & s.SubString(33,2) & "-"
    Dim ss As String
    ss=s.Remove(0,s.LastIndexOf("T0")+3)
    ss=ss.Remove(ss.IndexOf("="))
    Dim s2() As String =ss.Split(chr(13))
    OutPut.show(s2.Length)
    For i As Integer =0 To s2.Length-1
        Dim s3() As String =s2(i).Split(" ")
        If s3(0) > "" AndAlso s3(1) > "" AndAlso s3(2) > "" Then
            mmDate =Cdate(mmYM & (i+1))
            Dim rr As String = "mID = '" & mmID & "' And mDate = " & "#" & mmDate & "#"
            dr = DataTables("WeatherData").Find(rr)
            If dr IsNot Nothing  Then
                Dim r As Integer
                r = Tables("WeatherData").FindRow(rr, 0, True )
                If r >= 0 Then '如果找到的话
                    Tables("WeatherData").Position = r '定位到找到的行.
                End If
                Tables("WeatherData").Current("mT02")=s3(0)
                Tables("WeatherData").Current("mT08")=s3(1)
                Tables("WeatherData").Current("mT14")=s3(2)
                Tables("WeatherData").Current("mT20")=s3(3)
                Tables("WeatherData").Current("mGt")=s3(4)
                Tables("WeatherData").Current("mDt")=s3(5)
            Else
                DataTables("WeatherData").AddNew()
                Tables("WeatherData").Position=Tables("WeatherData").Position+1
                Tables("WeatherData").Current("mID")=mmID
                Tables("WeatherData").Current("mDate")=mmDate
                Tables("WeatherData").Current("mT02")=s3(0)
                Tables("WeatherData").Current("mT08")=s3(1)
                Tables("WeatherData").Current("mT14")=s3(2)
                Tables("WeatherData").Current("mT20")=s3(3)
                Tables("WeatherData").Current("mGt")=s3(4)
                Tables("WeatherData").Current("mDt")=s3(5)
            End If
        End If
    Next
Else
    MessageBox.Show("你未选择任何文件" ,"提示") '提示用户选择的文件
End If

 回到顶部