Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

Fill.DataSet according to Combobox->Items (Windows Form app) (no replies)

$
0
0
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);
}

}
}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>