Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using MySql.Data.MySqlClient;
- namespace fatoum.mysql._2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string MyConString = "SERVER=localhost;" +
- "DATABASE=a9895290_newedu;" +
- "UID=root;" +
- "PASSWORD=;";
- MySqlConnection connection = new MySqlConnection(MyConString);
- MySqlCommand command = connection.CreateCommand();
- MySqlDataReader Reader;
- command.CommandText = "select id,name from users where type = 4";
- try
- {
- connection.Open();
- }
- catch (MySqlException mse)
- {
- Console.WriteLine(mse.Message);
- Console.ReadKey();
- }
- Reader = command.ExecuteReader();
- var students = new List<string>();
- while (Reader.Read())
- {
- for (int i = 0; i < Reader.FieldCount; i++)
- students.Add(Reader.GetValue(i).ToString());
- }
- Reader.Close();
- string[] array1 = students.ToArray();
- string id_str = "";
- for (int i = 0; i < students.Count / 2; i = i + 2)
- {
- id_str += "`user` = \"" + students[i] + "\" OR ";
- }
- Console.WriteLine("Total of {0} ppl with this code", students.Count / 2, "\n");
- command.CommandText = "select user,result,unknown from results where (" + id_str + "0=1 ) and exam = 5";
- try
- {
- Reader = command.ExecuteReader();
- }
- catch
- {
- Console.Write(command.CommandText);
- Console.ReadKey();
- }
- int n = 0;
- int gazar = 0;
- var results = new List<string>();
- while (Reader.Read())
- {
- for (int i = 0; i < Reader.FieldCount; i++)
- {
- results.Add(Reader.GetValue(i).ToString());
- }
- /* for (int i = 0; i < Reader.FieldCount / 2; i = i + 2)
- {
- //Console.WriteLine("{0}: \"{1}\"\t\t!{2} \t ?{3}", array[i - 1], Reader.GetValue(0), array[i], array[i + 1]);
- try{
- Console.WriteLine(gazar++ + ":{0})\t{1}\t\t{2},\t left out:{3}", array[n],
- array[n + 1],
- Reader.GetValue(i),
- Reader.GetValue(i + 1));
- }catch{
- }
- } n = n + 2;*/
- }
- Console.WriteLine(results.Count);
- string[] array2 = results.ToArray();
- int index,m = 0;
- string first,second;
- for (int i = 0; i < students.Count; i = i + 2)
- {
- first = second = "n/a";
- if (Array.FindIndex(array2, t => t.IndexOf(array1[i], StringComparison.InvariantCultureIgnoreCase) >= 0) >= 0)
- {
- //StringComparison.InvariantCultureIgnoreCase
- index = Array.FindIndex(array2, t => t.IndexOf(array1[i], StringComparison.InvariantCultureIgnoreCase) >= 0);
- // index = Array.IndexOf(array2, array1[i].ToLower());
- first = array2[index + 1];
- second = array2[index + 2];
- ++m;
- }
- try
- {
- Console.WriteLine((++gazar) + ":{0})\t{1}\t\t{2},\t left out:{3}", array1[i],
- array1[i + 1],
- first,
- second);
- }
- catch
- {
- }
- }
- Console.WriteLine(m);
- Reader.Close();
- connection.Close();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement