Page 1 of 1

How to execute a query and check the results?

Posted: Thu 26 Jan 2012 21:52
by tsvetanakos
Hello! I'm really new in visual c++ and newer in dbforge.I have a question and hope that someone will answer it.I started a database application,but my problem is that I can't execute and see the query results.As I can see visual c++ have created 2 codes:

Code: Select all

// mySqlCommand1
			// 
			this->mySqlCommand1->CommandText = L"select *\r\nfrom Users";
			this->mySqlCommand1->Connection = this->mySqlConnection1;
			this->mySqlCommand1->Name = L"mySqlCommand1";
			this->mySqlCommand1->Owner = this;
			// 
			// mySqlConnection1
			// 
			this->mySqlConnection1->ConnectionString = L"User Id=programm;Host=*******.net;Database=programm;Password=14" 
				L"7****;";
			this->mySqlConnection1->Name = L"mySqlConnection1";
			this->mySqlConnection1->Owner = this;
Ok its very well made,but how can execute the mySqlCommand1 and see the results?
I have made a ritchtext box wich is supposed to show me the results:

Code: Select all

private: System::Void btntest_Click(System::Object^  sender, System::EventArgs^  e) {
				 box1-> Text = 
			 }
How am I supposed to print the results inthere?PLEASE help me!

any replay is highly appreciated!

THANKS in advance!

Posted: Fri 27 Jan 2012 14:02
by Pinturiccio
When you want to retrieve all the data, returned by query "select * from", you should use a MySqlDataReader object. You can change your code to retrieve data from database:

Code: Select all

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 System::String^ str="";
				 Devart::Data::MySql::MySqlDataReader^ reader=MySqlCommand1->ExecuteReader();
				 while (reader->Read())
				 {
					for (int i=0;iFieldCount;i++)
					{
						str+=reader->GetValue(i)+"\t";
					}
					str+="\n";
				 }
				 box1->Text=str;
			 }
For more details please refer to: http://www.devart.com/dotconnect/mysql/ ... eving.html
There are samples only for C# and Visual basic languages. So, if anything would be unclear, feel free to contact us.