0

I have a SQL database (local using vb.net) which has a table with 76 columns. The data that needs to be put into those columns is in the form of a plain delimited text file. I need to build a VB.NET application which will allow me to import the text file into the table in the database under their appropriate columns. Is there any way I can do this?

I'm very new to VB.NET. Can someone help me out with the code?

Thank You! Kamall

2 Answers 2

1

If you have comma-separated values:

bulk insert tableName
from 'C:\myfile.txt'
with (fieldterminator = ',', rowterminator = '\n')
go

For tab-separated values use:

bulk insert tableName
from 'C:\myfile.txt'
with (fieldterminator = ',', rowterminator = '\n')
go
Sign up to request clarification or add additional context in comments.

7 Comments

To clarify this is not VB.Net, it's T-SQL, and personally I think it's a much more simpler and effective solution
Why even bother with VB.Net it's just complicating it if you ask me.
Reason is, we are building a front-end application using vb.net and this application would help us in importing and manipulation the data from the underlying database
Really @Nick.McDermaid? @Kamall I need to know how familiar you are with database connectivity in VB.NET. Do you know how to establish a database connection with .NET code?
yes @marttronix, I was able to create a local DB and establish a connection to it using vb.net
|
0

76 columns ?
Must be the god-table antipattern ...

   Public Sub CopyToDataBase(dt As DataTable)

    Using Conn As SqlConnection = New SqlConnection("YOUR_CONNECTION_STRING")
        Conn.Open()

        Using s As SqlBulkCopy = New SqlBulkCopy(Conn)

            s.DestinationTableName = "TableName"
            s.WriteToServer(dt)
            s.Close()

        End Using

        Conn.Close()
    End Using
End Sub

of course this requires the table to have a primary key.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.