Dim fname As String = ""
If (dlgImportClients.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fname = dlgImportClients.FileName
End If
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()
'need to add false for checkbox column
TextLine = "False," + TextLine
SplitLine = Split(TextLine, ",")
dgvClients.ColumnCount = SplitLine.Count
dgvClients.MasterGridViewTemplate.AllowAddNewRow = False
dgvClients.ReadOnly = False
dgvClients.Columns(0).IsVisible = True
'if .RowCount = 0 then we are processing the first row
If dgvClients.RowCount = 0 Then
For i = 1 To SplitLine.Count - 1
With dgvClients
.Columns(i).HeaderText = SplitLine(i).ToString
.Columns(i).BestFit()
End With
Next
End If
dgvClients.Rows.Add(SplitLine)
Loop
'stupid but the only way I could get the datagridview to populate correctly
If dgvClients.RowCount > 1 Then
dgvClients.Rows.RemoveAt(0)
End If
Else
RadMessageBox.SetThemeName("Breeze")
RadMessageBox.Show("File Does Not Exist")
End If
I am loading the .CSV file to the GridView so that it can be reviewed, cleaned up, and then imported into Clients table within the customers database.
I'm kinda stumped as to the best way to get the data in the GridView into the database. Could just be a brain fart or I may be going about this totally wrong. Any insight would be greatly appreciated.