carte blanche
carte blanche

Reputation: 11476

mysql query not working

I am trying to write a MySQL query in C# as below,I don't see any errors but neither I see the required output, the query works fine in mysqlworkbench ,am using MySql.Data.dll connection 6.9.9,what am I missing?how to debug what is wrong?

        string connectionString = "server=10.xx.xxx.xx;database=databasename;uid=username;pwd=password;";

        var conn = new MySql.Data.MySqlClient.MySqlConnection();
        conn.ConnectionString = connectionString;
        try
        {
            Console.WriteLine("Connecting to MySQL...");
            conn.Open();

            string sql = "select bb.version,bb.baat,bb.au from build bb where bb.version='x.xxx' and bb.state='COMPLETE'";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(rdr[0] + " -- " + rdr[1]);
                Console.ReadLine();
            }
            rdr.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

Upvotes: 0

Views: 95

Answers (1)

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4191

try to change:

from rdr[0] 

to:

rdr.GetString(0)

Upvotes: 1

Related Questions