0

I tried the code in the answer to this question.

I tried the following code:

   static void Main(string[] args)
    {
        System.IO.File.WriteAllLines("myFile.csv",
            new[]
            {
                "a,b,c",
                "1,2,3",
                "4,5,6",
                "7,8,9"
            });

        const string cmd = @"create table myTable(a text, b text, c text);
                            .separator ','
                            .import  myFile.csv myTable";

        using (var conn = new SQLiteConnection("Data Source=test.db;Version=3;"))
        {
            conn.Open();

            var cmdExec = new SQLiteCommand(cmd, conn);
            cmdExec.ExecuteNonQuery();
        }
}

However, I get the following error:

SQL logic error
near ".": syntax error

Stack trace:

System.Data.SQLite
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
   at Reporting_Testing_Facility.Program.Main(String[] args) in C:\Users\SUE2MTP\Documents\Visual Studio 2015\Projects\Reporting Testing Facility\Reporting Testing Facility\Program.cs:line 127
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Is there a way to fix this? Or can this command only be used from the command line?

7
  • Where did you get this syntax from? Commented Aug 29, 2018 at 17:45
  • @juergend From the linked question. Commented Aug 29, 2018 at 17:45
  • 2
    There is a difference in between running a console import command and running a query inside the DB. Commented Aug 29, 2018 at 17:46
  • @juergend Yes, I suspected that it was related to that somehow - is there a way to run this programmatically (or do I have to run it from the command line)? Commented Aug 29, 2018 at 17:49
  • 1
    I think you are going to need to do it in 2 steps. Import to a table using OleDB, then save using SQLite provider. The NET provider doesnt have an import tool (AFAIK) Commented Aug 29, 2018 at 17:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.