Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

c# mysql print some ting on screen

I can connect c# to mysql
But how can   select *  from a where colum a like 1
 I want to count the value of row and print the number of row on screen
Avatar of kaufmed
kaufmed
Flag of United States of America image

Using the MySqlConnector, which I assume you have since you say you can connect, you would simple create a connection object and a command object and execute your query:

using (MySqlConnection con = new MySqlConnection("your_connection_string"))
{
    using (MySqlCommand cmd = new MySqlCommand("select count(*)  from a where colum a like 1", con))
    {
        int count = (int)cmd.ExecuteScalar();

        textBox1.Text = count.ToString();
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrTV

ASKER

Hi kaufmed

if i want to print in console application how can i do it

Thank
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In a console app, based on my earlier code:

Console.WriteLine(totalAsText);

Chris Bray
Instead of

textBox1.Text = count.ToString();

Open in new window


you would use:

Console.WriteLine(count.ToString());

Open in new window


and instead of

MessageBox.Show(ex.ToString());

Open in new window


you would use:

Console.WriteLine(ex.ToString());

Open in new window