mysql查询不起作用

时间:2017-03-23 04:51:56

标签: c# mysql

我正在尝试用C#编写一个MySQL查询,如下所示,我没有看到任何错误,但我没有看到所需的输出,查询在mysqlworkbench中工作正常,使用MySql.Data.dll连接6.9.9,我错过了什么?如何调试错误?

        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());
        }

1 个答案:

答案 0 :(得分:1)

尝试改变:

from rdr[0] 

为:

rdr.GetString(0)