Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. namespace ConsoleApplication2
  2. {
  3.     using System.Data.SQLite;
  4.     using System.Data;
  5.     using System;
  6.     internal class Program
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             //Open DB
  11.             SQLiteConnection conn = new SQLiteConnection(
  12.                 "Data Source=/Users/renurt/Desktop/log05.sq3; Version=3;");
  13.             conn.Open();
  14.  
  15.             //GET ONE VALUE
  16.             SQLiteCommand cmd = conn.CreateCommand();
  17.             cmd.CommandText = "SELECT activity FROM Events WHERE id = @param1";
  18.             cmd.Parameters.Add(new SQLiteParameter("@param1", 98));
  19.             var value = cmd.ExecuteScalar();
  20.             Console.WriteLine(value);
  21.  
  22.             //GET PLENTY VALUES
  23.             DataSet data = new DataSet();
  24.             data.Reset();
  25.             cmd.CommandText = "SELECT * FROM Events WHERE id < 98;";
  26.             SQLiteDataAdapter ad = new SQLiteDataAdapter(cmd);
  27.             ad.Fill(data);
  28.             //PRINTING DATASET
  29.             foreach (DataTable ds in data.Tables)
  30.             {
  31.                 for (int row = 0; row < ds.Rows.Count; row++)
  32.                 {
  33.                     for (int col = 0; col < ds.Columns.Count; col++)
  34.                     {
  35.                         Console.Write(ds.Rows[row][col].GetType().Name + "\t");
  36.                     }
  37.  
  38.                     Console.WriteLine();
  39.                 }
  40.             }
  41.  
  42.             //CLOSE DB
  43.             conn.Close();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement