使用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());
}
}
}
答案 0 :(得分:3)
ExecuteNonQuery不会为您提供输出,它会对连接执行Transact-SQL语句并返回受影响的行数。请改为ExecuteReader或BeginExecuteReader。这些链接还包含帮助您的示例: - )
您可能希望将其更改为:
while (reader.Read())
{
Name.Text = (reader[0].ToString());
}
答案 1 :(得分:2)