Solved

Inserting Text Paragraphs into MySQL DB from VB.NET

Posted on 2011-03-23
1
601 Views
Last Modified: 2012-05-11
I am trying to load portions of 300,000KB files into a table of MySQL database. The portions may contain many pages of news articles with various punctuation elements, including parethesis, quotes and semicolons.

I attempted to compile an "Insert" statement to insert the text, but for reasons realted to punctuation that failed miserably.  

Another approach I am considering is to dump the text into another data file "file.data" and initiate a bulk insert operation. The problem with that approach is I have many 300,000KB files I need to process and reading such large files from the hard drive, loading portions of these files in memory, creating temp file on the harddrive for bulk operations, then having MySQL Server read the temp files from the Hard Drive seens very slow and redundant.

There is got to be a simple way of sending data that is already stored in an object in memory as a packet to MySql Server for processing...

The points will be awarded to an expert who can advise how to efficiently load text stored in VB.NET StringCollection object into a MySQL DB table column of type "Text", while preserving the original formatting of the text.

Thank you.
0
Comment
Question by:cyber-33
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35202998
The only "punctuation" you should have to worry about when inserting text data into the DB is the single quote ( ' ) since that's what SQL Server uses to denote strings. All you should need to do is double-up single quotes in your source text. This is known as "escaping" and causes such a quote to be considered part of the data and not a string "marker." You could use a simple Replace() to do this:

    data = data.Replace("'", "''")  ' one single quote replaced by two singe quotes; all occurrence ls
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now