VC++ 2010 . How to diaplay MYSQL DATA(single row) TO a TEXTBOX.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a sql table and I want to display the table values to a (multiline) textbox field in win form. presently mycode displays only first value present in the sql database.
Heres the code.
<span style="white-space:pre //Show DB Button<br/>
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) <br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre <span style="white-space:pre int query_state;<br/>
<span style="white-space:pre mysql_init(&mysql);<br/>
<span style="white-space:pre connection = mysql_real_connect(&mysql,"localhost","root","root","weight",0,0,0);<br/>
<span style="white-space:pre if(connection == NULL)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre textBox3->Text="SQL Not Connected";<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre else <br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre std::string DOIT= "select * from weht";<br/>
<span style="white-space:pre query_state = mysql_query(connection,DOIT.c_str());<br/>
<span style="white-space:pre if (query_state != 0)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre textBox3->Text="query error";<span style="white-space:pre
<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre else<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre this->textBox1->Text="query success";<br/>
<span style="white-space:pre result = mysql_store_result(connection);<br/>
<span style="white-space:pre //while ((row = mysql_fetch_row(result)) != NULL )<br/>
<span style="white-space:pre {<span style="white-space:pre <br/>
<span style="white-space:pre row = mysql_fetch_row(result);<br/>
<span style="white-space:pre std::ostringstream o;<br/>
<span style="white-space:pre o << row[0];<br/>
<span style="white-space:pre std::string s(o.str());<span style="white-space:pre
<br/>
<span style="white-space:pre textBox3->Text= gcnew System::String(s.c_str());<span style="white-space:pre
<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre <span style="white-space:pre }<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre }

I thought the while loop will help me , but it didnt work. I have commented the while.
Please help me out.
thanks

View the full article
 
Back
Top