CodeXchange Friday, April 19, 2024
Home
What's it?
Download
Register
My Snippets
Add Snippet
Search
Faq
Contact Us
Sponsors

Website hosted by


Code Snippet Preview

Review the code snippet before inserting it on your project.

Snippet Metadata
Summary: Update SQL databace from CSV file
Language: VB.NET
Author: Mischa Princ
Author snippets RSS:
Culture: cs-CZ
Bytes: 2405
Visual Studio 2005 Snippet:

Snippet Stats
Downloads: 6
Overall rating : 0
Average rating : Snippet rating

Snippet Preview
Code:
Imports System.IO
Imports System.Text
    'Created : Mischa (mischa@piketa.cz)
Module cvs
    'CVS structure : 
    'Uniq ID;col1;col2;....
    '123;bla;bla bla

    Dim conn_path = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path\to\some\access_db.mdb"
    Dim path As String = "export.csv"
    Function hledej(ByVal retez As String, ByVal pole() As String)
        Dim zpet As String = ""
        For Each Str As String In pole
            If Str.Contains(retez) Then
                zpet = Str
            End If
        Next
        Return zpet
    End Function

    Sub Main()
        Using connect As New System.Data.OleDb.OleDbConnection(conn_path)
            connect.Open()

            Dim readText() As String = File.ReadAllLines(path)
            Dim radek As String
            Dim promenne() As String
            promenne = readText(0).Split(";")
            Dim a As Integer = 0
            For Each radek In readText
                If a > 0 Then
                    Dim prikaz As String
                    Dim pole() As String
                    pole = radek.Split(";")
                    Dim c As Integer = 1
                    Dim max As Integer = promenne.Length
                    While c < max
                        If pole(c) <> "" And promenne(c).ToString <> "" Then

                            prikaz = "UPDATE table SET " & "`" & RTrim(LTrim(promenne(c))) & "`='" & pole(c) & "'" & " WHERE `" & RTrim(LTrim(promenne(0))) & "`='" & pole(0) & "'"

                            Dim update As New System.Data.OleDb.OleDbCommand(prikaz, connect)
                            Try
                                update.ExecuteNonQuery()
                                Console.ForegroundColor = ConsoleColor.Red
                                Console.Write("-")
                                Console.ForegroundColor = ConsoleColor.Gray
                            Catch ex As Exception
                                Console.ForegroundColor = ConsoleColor.Red
                                Console.Write("*")
                                Console.ForegroundColor = ConsoleColor.Gray
                            End Try
                        End If
                        c += 1
                    End While

                End If
                a += 1
            Next
            Console.Read()

        End Using
    End Sub
End Module

Snippet Comments
Comments:
No comments for this snippet

Other snippets that may interest you..
Related Snippets
TDT - GridPage - Page_Init (C#)
CustomValitaor (C#)
(C#)
Get the file extension from a file path or file name (VB.NET)
grab record from db and subtracts it from variable (VB.NET)



Copyright ©2009-2024 CodeXchange. Server version 1.0.3720.32855 Client Version 0.9.0.0

With from Barcelona

Most Helpful members
These are the members who have received the most points for their helpful samples
Zepho Zep
Robert Wagner
Galen Taylor

All time 'Hall of fame'
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
INI File Access (VB.NET)
Read XML from string into DataSet (C#)
Create Manifest File for your Application (VB.NET)
Round function to avoid banker's rounding (VB.NET)
Get Short and Long Path Names (VB.NET)
Sending Mail through authenticated SMTP server (C#)
One Way Hash for strings (C#)
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
How do I load an image from a URI address? (VB.NET)
Use our easy to use Visual Studio.NET addin client and start sharing code snippets with the CodeXchange community!
Refreshed: Friday, April 19, 2024