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?

0 Answers0