VinylxScratches
Golden Member
I'm trying to write program that connects to a MySQL and does a select query.
I can connect to the server but it doesn't return anything.
Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MySqlConnection MyCon = new MySqlConnection("server=localhost;database=test2;uid=root;password=123456");
MySqlConnection connection = MyCon;
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT * FROM car;";
connection.Open();
Reader = command.ExecuteReader();
while(Reader.Read())
{
Console.Write("Record Found");
}
Reader.Close();
connection.Close();
}
}
}
I know it connects correctly because if I change the user name or anything from the connectionstring, the program will crash.
My MySQL DB is just called test2
table is called cars with columns
ID and Name
If I do a select query in MySQL query program I get this.
ID, Name
1, Dodge
2, Chevy
I know my app doesn't display data but I was hoping to get 2 rows saying "Record Found" at least.
I can connect to the server but it doesn't return anything.
Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MySqlConnection MyCon = new MySqlConnection("server=localhost;database=test2;uid=root;password=123456");
MySqlConnection connection = MyCon;
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT * FROM car;";
connection.Open();
Reader = command.ExecuteReader();
while(Reader.Read())
{
Console.Write("Record Found");
}
Reader.Close();
connection.Close();
}
}
}
I know it connects correctly because if I change the user name or anything from the connectionstring, the program will crash.
My MySQL DB is just called test2
table is called cars with columns
ID and Name
If I do a select query in MySQL query program I get this.
ID, Name
1, Dodge
2, Chevy
I know my app doesn't display data but I was hoping to get 2 rows saying "Record Found" at least.