tima18

Untitled

Jun 12th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.SQLite;
  7. using System.IO;
  8.  
  9. namespace PyCharm
  10. {
  11.     class Database
  12.     {
  13.         public SQLiteConnection Connect;
  14.  
  15.         public string connectionString { get; set; }
  16.  
  17.         string connection;
  18.        
  19.         //Создаем подключение к базе
  20.         public void getconnection()
  21.         {
  22.             connection = @"Data Source=Database.db; Version=3";
  23.             connectionString = connection;
  24.         }
  25.  
  26.         //Создаем базу
  27.  
  28.         public Database()
  29.         {
  30.             //проверка есть ли такая база
  31.             if (!File.Exists("./Database.db"))
  32.             {
  33.                 SQLiteConnection.CreateFile("Database.db");
  34.                 getconnection();
  35.                 using (SQLiteConnection con=new SQLiteConnection(connection))
  36.                 {
  37.                     SQLiteCommand command = new SQLiteCommand();
  38.                     con.Open();
  39.                     string query = @"CREATE TABLE LOGIN(Username nvarchar(25),Password nvarchar(25))";
  40.                     command.CommandText = query;
  41.                     command.Connection = con;
  42.                     command.ExecuteNonQuery();
  43.                     //закрываем подключение
  44.                     con.Close();
  45.                 }
  46.             }
  47.             else
  48.             {
  49.                 return;
  50.             }
  51.         }
  52.  
  53.     }
  54. }
Add Comment
Please, Sign In to add comment