Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!
List<string> UpdateList = new List<string>();
using (TextReader CSVDoc = new StreamReader(@"CSV path"))
DBFields = CSVDoc.ReadLine();
string TMPString = CSVDoc.ReadLine();
while (TMPString != null)
string TMPArray = TMPString.Split(',');
string InsertString = "";
for (int i = 0; i < TMPArray.Length; i++ )
InsertString += "'" + TMPArray[i] + ((i + 1 == TMPArray.Length) ? ("'") : ("', "));
UpdateList.Add("INSERT INTO *tablename* (" + DBFields + ") VALUES (" + InsertString + ");");
TMPString = CSVDoc.ReadLine();
Open in new window
Private Function GetInsertQueriesFromCSV(ByVal iFile As String) As List(Of String)
Dim UpdateList As New List(Of String)
Dim DBFields As String = ""
Using CSVDoc As TextReader = New StreamReader(iFile)
DBFields = CSVDoc.ReadLine()
Dim TMPString As String = CSVDoc.ReadLine()
While TMPString IsNot Nothing
Dim TMPArray() As String = TMPString.Split(",")
Dim InsertString As String = ""
For i = 0 To TMPArray.Length - 1 Step 1
InsertString += "'" + TMPArray(i) + If(i + 1 = TMPArray.Length, "'", "', ")
UpdateList.Add("INSERT INTO *tablename* (" + DBFields + ") VALUES (" + InsertString + ");")
TMPString = CSVDoc.ReadLine()
Catch ex As Exception
Private Sub InsertIntoDB(ByVal iList)
Using SqlConn As New OdbcConnection("ConnectionString")
Dim SqlComm As New OdbcCommand()
SqlComm.Connection = SqlConn
If SqlConn.State <> ConnectionState.Open Then
Throw New Exception("The connection is not open :S")
For Each Query As String In iList
SqlComm.CommandText = Query
If (SqlComm.ExecuteNonQuery() = 0) Then
MessageBox.Show(Query, "Malformed Query")
Catch ex As Exception
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.