Есть ли простой способ перебрать сетку данных и заменить или удалить определенный символ - PullRequest
0 голосов
/ 01 мая 2019

У меня есть таблица данных, заполненная из .csv, .csv разделена запятой.CSV также содержит запятые в строковых полях, что мешает загрузке его в сетку данных, файл CSV также имеет символ ', который путается с отправкой в ​​БД позже.

вместо того, чтобы "чистить" файл перед загрузкой,Есть ли простой способ сканирования загруженной сетки и удаления этих символов?Или лучше сначала очистить файл?

спасибо заранее

очистка файла перед загрузкой, кажется, работает нормально.

код загрузки:

 Dim TextLine As String = ""
    Dim SplitLine() As String

    If System.IO.File.Exists(fname) = True Then
        Dim objReader As New System.IO.StreamReader(fname)

        Do While objReader.Peek() <> -1
            TextLine = objReader.ReadLine()
            SplitLine = Split(TextLine.Replace("""", ""), ",")
            'SplitLine = Split(TextLine, ",")
            grdDisplay.ColumnCount = SplitLine.Count
            grdDisplay.Rows.Add(SplitLine)
        Loop
        objReader.Close()
        objReader.Dispose()
        grdDisplay.AutoResizeColumns()

    Else
        MessageBox.Show("File Does Not Exist")

    End If

Отправить в БД код:

Dim cm As New SqlCommand с cm .Connection = cn

        For i As Integer = 1 To grdDisplay.RowCount - 1
            .CommandText = "insert into DefectRequestEntries values 
            ('" & grdDisplay.Rows(i).Cells(0).Value & "','  " & grdDisplay.Rows(i).Cells(1).Value & "','
              " & grdDisplay.Rows(i).Cells(2).Value & " ',' " & grdDisplay.Rows(i).Cells(3).Value & "','
              " & grdDisplay.Rows(i).Cells(4).Value & " ',' " & grdDisplay.Rows(i).Cells(5).Value & "','
              " & grdDisplay.Rows(i).Cells(6).Value & " ',' " & grdDisplay.Rows(i).Cells(7).Value & "','
              " & grdDisplay.Rows(i).Cells(8).Value & " ',' " & grdDisplay.Rows(i).Cells(9).Value & "','
              " & grdDisplay.Rows(i).Cells(10).Value & " ',' " & grdDisplay.Rows(i).Cells(11).Value & "','
              " & (grdDisplay.Rows(i).Cells(12).Value & "')")

            .ExecuteNonQuery()
        Next
    End With
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...