开发者

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

开发者 https://www.devze.com 2023-02-16 19:56 出处:网络
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=gym

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

精彩评论

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

关注公众号