Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.OleDb;
  6. using System.Data.Odbc;
  7. using System.Data.SqlClient;
  8.  
  9.  
  10. namespace ConsoleApplication1
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine("Start!");
  17.             OdbcConnection myConnection = new OdbcConnection("Driver={mySQL};Server=192.168.1.110;Option=16834;Database=MYDB;User=mydb;Password=mydb;");
  18.             Console.WriteLine("Start2!");
  19.             try
  20.             {
  21.                 myConnection.Open();
  22.                 Console.WriteLine("Start3!");
  23.             }
  24.             catch (Exception e)
  25.             {
  26.                 Console.WriteLine(e.ToString());
  27.             }
  28.            
  29.            
  30.  
  31.             try
  32.             {
  33.                 OdbcCommand myCommand = new OdbcCommand("Select * from mytable", myConnection);
  34.                 OdbcDataReader myReader = myCommand.ExecuteReader();
  35.  
  36.                 Console.Write("Here\n");
  37.                 while (myReader.Read())
  38.                 {
  39.                     for (int i = 0; i < myReader.FieldCount; i++)
  40.                     {
  41.                         Console.Write(myReader[i] + " ");
  42.                     }
  43.                     Console.Write("\n");
  44.                 }
  45.             }
  46.             catch (Exception e)
  47.             {
  48.                 Console.WriteLine(e.ToString());
  49.             }
  50.             myConnection.Close();
  51.             while (true)
  52.             {
  53.  
  54.             }
  55.            
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement