Exemplo n.º 1
0
        public static void Sample_String_To_Sqlite()
        {
            string data = @"Name;Address;Gpnr
John;Main Road; 4711
Jeffrey;;4712
Mike;Hauptstr.1;4713";

            string sampleDataPath = @"..\..\Samples\";
            var    watch          = new Stopwatch();

            using (Stream stream = StreamUtil.CreateStream(data))
            {
                using (var reader = new CsvAdapter(stream))
                {
                    reader.Separator = ";";

                    using (var writer = new SqliteAdapter())
                    {
                        writer.FileName = sampleDataPath + @"stringdata.sqlite";
                        writer.CreateNewFile();
                        writer.TableName = "Tabelle1";

                        if (!writer.Connect())
                        {
                            throw new Exception("No connection");
                        }

                        watch.Start();
                        int lineCount = 0;

                        reader.ReadData(30)
                        .ForEach(x =>
                        {
                            Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count);
                            lineCount += x.Rows.Count;
                        })
                        .Do(x => writer.WriteData(x));

                        watch.Stop();
                        Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed);
                        Console.ReadLine();
                    }
                }
            }
        }