· 6 years ago · Dec 27, 2019, 11:32 AM
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Data.SQLite;
6using System.Drawing;
7using System.Linq;
8using System.Text;
9using System.Threading.Tasks;
10using System.Windows.Forms;
11
12namespace EveHelper
13{
14 public partial class Form1 : Form
15 {
16 public Form1()
17 {
18 InitializeComponent();
19 }
20
21 private void Button1_Click(object sender, EventArgs e)
22 {
23 SQLiteConnection connection = new SQLiteConnection($"Data Source=../test.db;Version=3;");
24 connection.Open();
25
26 SQLiteCommand command = new SQLiteCommand(connection);
27
28 command.CommandText = $"CREATE TABLE IF NOT EXISTS Item (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)";
29 int result = command.ExecuteNonQuery();
30
31 //Random r = new Random(Guid.NewGuid().GetHashCode());
32 //List<string> items = new List<string>();
33 //for (int i = 0; i < 10; i++)
34 //{
35 // string name = string.Empty;
36 // int letters = r.Next(10, 20);
37 // for(int j = 0; j < letters; j++)
38 // {
39 // name += (char)r.Next('a', 'z' + 1);
40 // }
41 // items.Add(name);
42 //}
43 //command.CommandText = $"INSERT INTO Item (name) VALUES {string.Join(",", items.Select(v => $"('{v}')"))}";
44 //command.ExecuteNonQuery();
45
46 SQLiteDataAdapter adapter = new SQLiteDataAdapter("SELECT * FROM Item", connection);
47 DataTable dataTable = new DataTable();
48 adapter.Fill(dataTable);
49
50 foreach (DataRow row in dataTable.Rows)
51 {
52 foreach (var item in row.ItemArray)
53 {
54 Console.Write($"{item}\t");
55 }
56 Console.WriteLine();
57 }
58
59 connection.Close();
60
61 }
62 }
63}