Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助从TXT导入文件中删除元素吗?该文件现在已更改,并使用VB.net导入到SQL中_Vb.net_Concatenation - Fatal编程技术网

需要帮助从TXT导入文件中删除元素吗?该文件现在已更改,并使用VB.net导入到SQL中

需要帮助从TXT导入文件中删除元素吗?该文件现在已更改,并使用VB.net导入到SQL中,vb.net,concatenation,Vb.net,Concatenation,我们有一个小的.NETVB应用程序,它读取由我们的打卡机创建的文本文件 然后,这些信息被存储到SQL数据库中 过去的数据行如下图所示 5208,05/06/2013,06:27:18,1 这是一个ID、日期、时间和时钟值 将文本拆分并为sql做好准备的代码如下所示: For Each fileInfo As FileInfo In allFiles If fileInfo.Length > 0 Then

我们有一个小的.NETVB应用程序,它读取由我们的打卡机创建的文本文件

然后,这些信息被存储到SQL数据库中

过去的数据行如下图所示

5208,05/06/2013,06:27:18,1

这是一个ID、日期、时间和时钟值

将文本拆分并为sql做好准备的代码如下所示:

            For Each fileInfo As FileInfo In allFiles
                If fileInfo.Length > 0 Then
                    If fileInfo.LastWriteTime <> Now Then
                        System.Threading.Thread.Sleep(500)
                        Dim srReader As New StreamReader(fileInfo.FullName.ToString)
                        strSplit = Split(srReader.ReadToEnd(), Chr(13))
                        srReader.Close()
                        srReader.Dispose()
                        srReader = Nothing
                        For intInner As Integer = 0 To strSplit.Length - 1
                            strInnerSplit = Split(strSplit(intInner), ",")
                            If strInnerSplit.Length > 3 Then
                                Dim strCard As Integer = strInnerSplit(0)
                                Dim intType As Integer = strInnerSplit(3)
                                Dim dteInOut As Date = strInnerSplit(2)
                                Dim dteDate As Date = strInnerSplit(1)

                                If alreadyInsertedWithinSQL(strCard, dteDate & " " & dteInOut, intType) = False Then
                                    importWithinSQL(strCard, dteDate & " " & dteInOut, intType)
                                End If
                            End If
                        Next
                    End If
                End If
            Next
        End If
将每个文件信息作为所有文件中的文件信息
如果fileInfo.Length>0,则
如果fileInfo.LastWriteTime现在生效,则
系统线程线程睡眠(500)
Dim srReader作为新的StreamReader(fileInfo.FullName.ToString)
strSplit=Split(srReader.ReadToEnd(),Chr(13))
srReader.Close()
srReader.Dispose()
srReader=无
对于intInner,整数=0到strSplit.Length-1
strInnerSplit=拆分(strSplit(intInner),“,”)
如果strInnerSplit.长度>3,则
作为整数的Dim strCard=strInnerSplit(0)
作为整数的Dim intType=strInnerSplit(3)
Dim dteInOut As Date=strInnerSplit(2)
Dim dteDate As Date=strInnerSplit(1)
如果alreadyInsertedWithinSQL(strCard,dteDate&&dteInOut,intType)=False,则
importWithinSQL(strCard、dteDate&&&dteInOut、intType)
如果结束
如果结束
下一个
如果结束
如果结束
下一个
如果结束
我们现在有一个问题,因为计时机器的格式已经改变,在文件前面包含了一些我们不需要的额外信息

办公室%5197,04/06/2013,22:08:54,2

小于等于%的第一个元素是固定宽度,并且始终具有%

是否有一个简单的方法可以在代码中删除此内容,以便我们只捕获5197,04/06/2013,22:08:54,2,或者是重写,因为我不是开发人员,只是继承了这个问题

干杯


约翰

像这样的事情应该行得通:

                    For intInner As Integer = 0 To strSplit.Length - 1
                        strInnerSplit = Split(strSplit(intInner), ",")
                        If strInnerSplit.Length > 3 Then
                            'Use the split method on the % and use the second
                            'element which is index 1
                            Dim strCard As Integer = strInnerSplit(0).Split("%")(1)
                            Dim intType As Integer = strInnerSplit(3)
                            Dim dteInOut As Date = strInnerSplit(2)
                            Dim dteDate As Date = strInnerSplit(1)

                            If alreadyInsertedWithinSQL(strCard, dteDate & " " & dteInOut, intType) = False Then
                                importWithinSQL(strCard, dteDate & " " & dteInOut, intType)
                            End If
                        End If
                    Next
也许像这样

声明字符串变量<代码>作为字符串的Dim s

                        For intInner As Integer = 0 To strSplit.Length - 1
                            s=Split(strSplit(intInner), "%")(1)
                            strInnerSplit = Split(s, ",")
                            If strInnerSplit.Length > 3 Then
                                Dim strCard As Integer = strInnerSplit(0)
                                Dim intType As Integer = strInnerSplit(3)
                                Dim dteInOut As Date = strInnerSplit(2)
                                Dim dteDate As Date = strInnerSplit(1)

                                If alreadyInsertedWithinSQL(strCard, dteDate & " " & dteInOut, intType) = False Then
                                    importWithinSQL(strCard, dteDate & " " & dteInOut, intType)
                                End If
                            End If
                        Next