使用odbc如何从表中选择内容并输出到asp.net页上的标签?

    {

        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=root; Password=;");
        cn.Open();
        OdbcCommand cmd = new OdbcCommand("SELECT * FROM User (FirstName, SecondName)", cn);
        OdbcDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            Name.Text = (reader[0].ToString());

        }
    }

}

最佳答案

ExecuteNonQuery不会提供输出,它会对连接执行Transact-SQL语句并返回受影响的行数。请参见ExecuteReaderBeginExecuteReader。这些链接还包含帮助您的示例:-)
您可能需要将其更改为:

while (reader.Read())
{
      Name.Text = (reader[0].ToString());
}

10-08 19:45