Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Threading.Tasks;
- using System.Data.SQLite;
- using MySql.Data;
- using MySql.Data.MySqlClient;
- namespace adonet_4
- {
- class Program
- {
- static void exec_sqlite(SQLiteCommand command)
- {
- try
- {
- SQLiteDataReader reader = command.ExecuteReader();
- do
- {
- while (reader.Read())
- {
- Object[] values = new Object[reader.FieldCount];
- int fieldCount = reader.GetValues(values);
- for (int i = 0; i < fieldCount; i++)
- {
- Console.Write("\t{0}", values[i]);
- }
- Console.WriteLine();
- }
- } while (reader.NextResult());
- reader.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine();
- }
- static void exec_mysql(MySqlCommand command)
- {
- try
- {
- MySqlDataReader reader = command.ExecuteReader();
- do
- {
- while (reader.Read())
- {
- Object[] values = new Object[reader.FieldCount];
- int fieldCount = reader.GetValues(values);
- for (int i = 0; i < fieldCount; i++)
- {
- Console.Write("\t{0}", values[i]);
- }
- Console.WriteLine();
- }
- } while (reader.NextResult());
- reader.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine();
- }
- static void Main(string[] args)
- {
- string conn_string_sqlite = @"Data Source=C:\Users\anthony\Documents\tbmstu.db; Version=3";
- SQLiteConnection conn1 = new SQLiteConnection(conn_string_sqlite);
- try
- {
- conn1.Open();
- Console.WriteLine("all good. sqlite");
- }
- catch (SQLiteException e)
- {
- Console.WriteLine(e.Message);
- }
- SQLiteCommand cmd1 = new SQLiteCommand("select * from persons", conn1);
- exec_sqlite(cmd1);
- conn1.Dispose();
- string conn_string_mysql = "Server=localhost;Uid=uid;Pwd=pwd;Database=db1;";
- MySqlConnection conn2 = new MySqlConnection(conn_string_mysql);
- try
- {
- conn2.Open();
- Console.WriteLine("all good. mysql");
- }
- catch (SQLiteException e)
- {
- Console.WriteLine(e.Message);
- }
- MySqlCommand cmd2 = new MySqlCommand("select * from t", conn2);
- exec_mysql(cmd2);
- conn2.Dispose();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement