开发者

how do I select something from a table and output to a label?

Using odbc how do I select something from a table and output to a label on my asp.net page?

    {

        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; 开发者_StackOverflow中文版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 will not give you a output, it executes a Transact-SQL statement against the connection and returns the number of rows affected. See ExecuteReader or BeginExecuteReader instead. These links also contain examples to help you :-)

You might want to change it to something like:

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


Take a look at the OdbcDataReader class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜