Page 1 of 1

Query result displayed in a textbox instead datatable?

Posted: Mon 19 Jun 2006 11:22
by Communi
How can I display a result of a query in a textbox instead of a datatable or a grid? The result is only a number (Select SUM()...) that should be displayed in a formatted textbox.
Should I use the MySqlText object or is there a quick solution for this?

Thanks!!

Posted: Mon 19 Jun 2006 11:29
by Alexey
You may use MySqlDataReader object to return the number
(Select SUM()...)
and then assign that number to a TextBox like this:

Code: Select all

textBox1.Text = reader[0].ToString();

Posted: Mon 19 Jun 2006 11:55
by Communi
This doesn't work :-(
There comes the message: "The value of CoreLab.MySql.MySqlDataReader cannot converted to a string"
Whats wrong there?

Posted: Mon 19 Jun 2006 12:17
by Alexey
I see this error first time.
Try to use the following statement:

Code: Select all

textBox1.Text = mySqlCommand1.ExecuteScalar().ToString();

Posted: Mon 19 Jun 2006 12:38
by Communi
Yes, now it works! Thank you very much, you make a really good job!!!!

Posted: Wed 21 Jun 2006 06:50
by Alexey
You are welcome