· 8 years ago · Feb 07, 2018, 10:04 AM
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.Data.SQLite;
11using System.IO;
12
13namespace seznam3._3
14{
15 public partial class Form1 : Form
16 {
17 SQLiteDataAdapter datadapter;
18 DataSet ds = new System.Data.DataSet();
19 SQLiteConnection sqlite_conn;
20
21 public Form1()
22 {
23 InitializeComponent();
24 }
25
26 private void Form1_Load(object sender, EventArgs e)
27 {
28
29 SQLiteDataReader sqlite_datareader;
30 sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
31 // open the connection:
32 sqlite_conn.Open();
33
34 SQLiteCommand sqlite_cmd;
35 sqlite_cmd = sqlite_conn.CreateCommand();
36 sqlite_cmd.CommandText = "CREATE TABLE IF NOT EXISTS Seznam(ID INTEGER PRIMARY KEY ASC,jmeno,prijmeni, bydliste, rok INTEGER, cislo INTEGER);";
37 sqlite_cmd.ExecuteNonQuery();
38
39 datadapter = new SQLiteDataAdapter("SELECT * FROM Seznam", sqlite_conn);
40
41 datadapter.Fill(ds, "info");
42 dataGridView1.DataSource = ds.Tables[0];
43 }
44
45 private void button1_Click(object sender, EventArgs e)
46 {
47 SQLiteCommandBuilder cmdb1;
48 cmdb1 = new SQLiteCommandBuilder(datadapter);
49
50 datadapter.Update(ds, "info");
51 }
52
53 private void button2_Click(object sender, EventArgs e)
54 {
55 if (this.dataGridView1.SelectedRows.Count > 0)
56 {
57 dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
58 }
59 }
60
61 }
62}