Advertisement
Guest User

Untitled

a guest
May 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using System.IO;
  7. using MySql.Data.MySqlClient;
  8.  
  9. using System.Data;
  10.  
  11. namespace ConsoleApplication1
  12. {
  13.     class Program
  14.     {
  15.         public static string SQLuser;
  16.         public static string SQLpassword;
  17.         static void Main(string[] args)
  18.         {
  19.             readconfigfile();
  20.             string connectionString = "Server=sql;" +
  21.                 "Database=u_chzz_stalkbot;" +
  22.                 "User ID=" + SQLuser + ";" +
  23.                 "Password=" + SQLpassword + ";" +
  24.                 "Persist Security Info=True;";
  25.  
  26.             MySqlConnection conn = new MySqlConnection(connectionString);
  27.             conn.Open();
  28.  
  29.             string SQLStatement = "SELECT * FROM channel";
  30.             MySqlDataAdapter ChanAdapter = new MySqlDataAdapter(SQLStatement, conn);
  31.             DataTable dtResult = new DataTable();
  32.             DataTable dtstalk = new DataTable();
  33.  
  34.             // Fill the DataTable with the result of the SQL statement
  35.             ChanAdapter.Fill(dtResult);
  36.  
  37.             // Loop through all entries
  38.            
  39.             foreach (DataRow drRow in dtResult.Rows)
  40.             {
  41.                 string thischan = drRow["Name"].ToString();
  42.                 Console.WriteLine(thischan);
  43.                 //now, for each channel, populate array of stalks
  44.                 SQLStatement = "SELECT text FROM chanstalk WHERE channel = '"+thischan+"'";
  45.                 Console.WriteLine(SQLStatement);
  46.                 MySqlDataAdapter stalkAdapter = new MySqlDataAdapter(SQLStatement, conn);
  47.                 DataTable stResult = new DataTable();
  48.                 stalkAdapter.Fill(stResult);
  49.                 dtstalk.Rows.Add(stResult);
  50.                 foreach (DataRow stRow in stResult.Rows)
  51.                 {
  52.                     string thisstalk = stRow["text"].ToString();
  53.                     Console.WriteLine("****"+thisstalk);
  54.  
  55.                 }
  56.                 stalkAdapter.Dispose();
  57.             }
  58.             // We don't need the data adapter any more
  59.             ChanAdapter.Dispose();
  60.             conn.Close();
  61.             conn.Dispose();
  62.             Console.WriteLine("XXXXXXX");
  63.          foreach (DataRow row in dtstalk.Rows)
  64.          {
  65.              Console.WriteLine("Row"+row);
  66.              foreach (DataColumn col in dtstalk.Columns)
  67.              {
  68.                  Console.WriteLine("col" + col);
  69.                  Console.WriteLine(row[col]);
  70.              }
  71.          }
  72.  
  73.  
  74.         }
  75.                 static void readconfigfile()
  76.         {
  77.             Console.WriteLine("reading .my.cnf");
  78.             StreamReader settingsreader = new StreamReader("/home/chzz/.my.cnf");
  79.             try {
  80.                settingsreader.ReadLine();
  81.                SQLuser = settingsreader.ReadLine();
  82.                SQLuser = SQLuser.Remove(0,SQLuser.IndexOf("=")+2);
  83.                SQLpassword = settingsreader.ReadLine();
  84.                SQLpassword = SQLpassword.Remove(0, SQLpassword.IndexOf("=") + 2);
  85.               // SQLpassword = SQLpassword.Replace("\"","");
  86.             }
  87.             catch (Exception ex) {
  88.                 Console.WriteLine("Could not read .my.cnf for SQL user/password");
  89.                 Console.WriteLine(ex.Message);
  90.             }
  91.        
  92.         }
  93.  
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement