Display Sql query result

  • Thread starter Thread starter Tomiwah
  • Start date Start date
T

Tomiwah

Guest



i have a c++ form that accepts data and saves it on a table in a database via a button click, this is the code for the event

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDatabase=gcnew MySqlCommand("insert into test.Data(Full_Name,Matric_No) values("+this->textBox1->Text+","+this->textBox10->Text+") ;" ,conDatabase);
MySqlDataReader^ myReader;
try{
conDatabase->Open();
myReader=cmdDatabase->ExecuteReader();

MessageBox::Show("Saved");
while(myReader->Read()){

}
}catch(Exception^ex){
MessageBox::Show(ex->Message);
}



NOW i want to send a query to give out this information in a new form or in a form exactly like the one used to enter the data, this is how far i have come

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
MyForm ^ Form = gcnew MyForm(this);
Form->ShowDialog();
String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDatabase=gcnew MySqlCommand("Select * from test.Data where Matric_No="+textBox1->Text +";",conDatabase);
MySqlDataReader^ myReader;
try{
conDatabase->Open();
myReader=cmdDatabase->ExecuteReader();
while(myReader->Read()){


textBox1->Text ;
}
}catch(Exception^ex){
MessageBox::Show(ex->Message);

}
}


NOte: MyForm is the title of the form used to enter in the data sent to the database please how do i get the program to display the data meeting the query criteria into a form?

Continue reading...
 
Back
Top