Search code examples
vb.netvisual-studio-2008sql-server-cecsv

Text Delimited into SQL Server CE


I have a comma delimited text file which I would like to add to a SQL Server CE database, I know how to do this in SQL Server but not for SQL Server CE using VB.Net.

Will it be a case of having to loop through each line in the file? It's quite a large file.

Thanks


Solution

  • Well, first I would use the textfieldparser to import the file. Next, you should only have to configure the connection for your SQLCE db and treat it like a normal SQL db from there. Here is a snippet from SO:

    Imports System.Data.SqlServerCe
    Imports System.Data
    
    Dim connection As New SqlCeConnection("Data Source=|DataDirectory|\<yourdb>.sdf")
    Dim command As New SqlCeCommand("SELECT * FROM Names", connection)
    Dim dataAdapter As New SqlCeDataAdapter(command)
    Dim ds As New DataSet()
    dataAdapter.Fill(ds)