Solved

In vb.net, best way to open, parse a text file into single column list box, then export listbox items to a multi column SQL tbl

Posted on 2008-10-15
2
992 Views
Last Modified: 2013-11-18
So, I take a text file, or paste some text into my text box....
I want to parse the text file into individual lines to display in a list box, then, once user is satisfied, be able to save the list box items into the relevant SQL table,
1st, import the file into the text box
(see code snippet)
Then, parse into the listbox
(see code snippet)

Now how best to (when user clicks "save") transfer those items from the listbox to fill in a 'requirement' column in the SQL table, populating the rest of the table columns with either default values, or values set on a parent form?

I've seen too many ways of doing it. BULK COPY vs. iterating? This will likely never be MASSIVE amounts of data, so bulk copy might be overkill...

This is probably simpler than I'm making it sound...(and that's half my problem). Thanks in advance.



Private Sub btn_Import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Import.Click
        Try
            With Me
                With .OpenFileDialog1
                    .Filter = "All Files(*.*)|*.*|Word(*.doc)|*.doc|RichTextFormat(*.rtf)|*.rtf|Text(*.txt)|*.txt|Log(*.log)|*.log"
                    .FilterIndex = 1
                    .InitialDirectory = "c:\working"
                    .Title = "File to Import"
                    .ShowDialog()
                    _filename = .FileName
                End With
                .txtParagraphs.Text = My.Computer.FileSystem.ReadAllText(_filename)
            End With
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub
'My parse function
    Private Function SplitSentences(ByVal sSourceText As String) As ArrayList
        Dim sTemp As String = sSourceText
        ' create the array list 
        Dim al As New ArrayList()
        ' split the sentences with a regular expression
        Dim RegexSentenceParse As String() = Regex.Split(sTemp, "(?<=['""A-Za-z0-9][\.\!\?])\s+(?=[A-Z])")
        ' loop the sentences
        Dim i As Integer = 0
        For i = 0 To RegexSentenceParse.Length - 1
            ' clean up and add to the array
            Dim sSingleSentence As String = RegexSentenceParse(i).Replace(Environment.NewLine, String.Empty)
            al.Add(sSingleSentence.Trim())
        Next
        Return al
    End Function
'Parse Text button
    Private Sub btn_Parse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Parse.Click
        Try
            With Me
                lstSentences.Items.Clear()
                Dim al As New ArrayList()
                al = SplitSentences(txtParagraphs.Text)
            Dim i As Integer
                For i = 0 To al.Count - 1
                    'populate the list box
                    lstSentences.Items.Add(al(i).ToString())
                Next
            End With
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

Open in new window

scrnshot1.JPG
0
Comment
Question by:1stcyberian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 300 total points
ID: 22734352
You can always send the data in to SQL as XML.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql query 107 87
Help Required 2 46
Problem to copy file 14 47
VBA: copy range dynamically based on config sheet v3 6 28
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question