以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 高手帮忙排下错,谢谢 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=19272) |
-- 作者:cxqxjyzg -- 发布时间:2012/5/4 10:59:00 -- 高手帮忙排下错,谢谢 下面的代码,我的目的是:从一个文本文件读入我需要的数据加载到WeatherData表里面,在加数据的时候先判断某日数据是否存在,如果存在,则替换相应数据,如果不存在,说明这个日期(这个日期不允许重复)没有数据,新增一行,再加载数据。 现在能加数据了,问题是如果多次加入数据会多出空行来,这个空行是那里产生的,请帮忙排查下,我看了N遍也找不到原因,谢谢!!
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog \'output.show("找到:" & Tables("WeatherData").Position) |
-- 作者:狐狸爸爸 -- 发布时间: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 |