MySQL Forums
Forum List  »  Connector/C++

Fill.DataSet according to Combobox->Items (Windows Form app)
Posted by: Ismael Fadiga
Date: November 17, 2014 03:27PM

Hi All,

Does anyone know from the below code, why my data table is not refreshed and updated accordingly, each time a combobox item is selected?

Any feedback would be very appreciated.

Cheers


private: System::Void btnconn_Click(System::Object^ sender, System::EventArgs^ e) {
if (cbbf->Items[0]=="items1")
{
String^ constring=L"Data Source=localhost;Port=3306;username=root;password=xxxx";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from world.city",conDataBase);

try{
conDataBase->Open();
MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
sda->SelectCommand=CmdDataBase;
DataTable^dbdataset=gcnew DataTable();
sda->Fill(dbdataset);
BindingSource^bSource=gcnew BindingSource();
bSource->DataSource=dbdataset;
dtGrid->DataSource=bSource;
//sda->Update(dbdataset);

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

}
else if (cbbf->Items[1]=="items2")
{
String^ constring=L"Data Source=localhost;Port=3306;username=root;password=xxxx";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from world.country",conDataBase);

try{
conDataBase->Open();
MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
sda->SelectCommand=CmdDataBase;
DataTable^dbdataset1=gcnew DataTable();
sda->Fill(dbdataset1);
BindingSource^bSource=gcnew BindingSource();
bSource->DataSource=dbdataset1;
dtGrid->DataSource=bSource;
sda->Update(dbdataset1);

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

}
else if (cbbf->Items[2]=="items3")
{
String^ constring=L"Data Source=localhost;Port=3306;username=root;password=xxxx";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from sakila.actor",conDataBase);

try{
conDataBase->Open();
MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
sda->SelectCommand=CmdDataBase;
DataTable^dbdataset2=gcnew DataTable();
sda->Fill(dbdataset2);
BindingSource^bSource=gcnew BindingSource();
bSource->DataSource=dbdataset2;
dtGrid->DataSource=bSource;
sda->Update(dbdataset2);

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

}
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Fill.DataSet according to Combobox->Items (Windows Form app)
2343
November 17, 2014 03:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.