Advertisement
estevaorada

Banco.cs - Basico

Jun 4th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Data;
  8. using System.Data.SQLite;
  9.  
  10. namespace RestauranteSenac.db
  11. {
  12. class Banco
  13. {
  14. // Objeto de conexão SQL:
  15. public SQLiteConnection conexao;
  16.  
  17. // Contrutor de conexão:
  18. public Banco()
  19. {
  20. // Apontar onde estará nosso arquivo de banco de dados:
  21. conexao = new SQLiteConnection("Data Source=banco.sqlite3");
  22. // Verificar se o arquivo banco.sqlite3 NÃO existe:
  23. if (!File.Exists("./banco.sqlite3"))
  24. {
  25. // Criar o arquivo de banco de dados:
  26. SQLiteConnection.CreateFile("banco.sqlite3");
  27. }
  28. }
  29. // Método para conectar:
  30. public void Conectar()
  31. {
  32. // Verificar se a conexão não está aberta:
  33. if(conexao.State != ConnectionState.Open)
  34. {
  35. // Abrir a conexão:
  36. conexao.Open();
  37. }
  38. }
  39.  
  40. // Método para desconectar:
  41. public void Desconectar()More actions
  42. {
  43. // Verificar se a conexão não está fechada:
  44. if(conexao.State != ConnectionState.Closed)
  45. {
  46. // Fechar a conexão:
  47. conexao.Close();
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement