Home > Net >  C # dynamic connection MySQL access database list to fill in the comboBox
C # dynamic connection MySQL access database list to fill in the comboBox

Time:09-15

C # form


Use demand access button, click on the lower right corner is right in the database will be listed under the current connection information database list, but now click many times is not possible,
Hope to master a great god can help me with, be obliged!

Part of the script below
 
Private DataTable getTable (string STR)
{
Try
{
MySqlConnection mysqlcon=new MySqlConnection (STR);
MySqlDataAdapter da=new MySqlDataAdapter (@ "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA. SCHEMATA)", mysqlcon);
The DataTable dt=new DataTable (" INFORMATION_SCHEMA. SCHEMATA ");
Da. The Fill (dt);
Return dt.
}
Catch
{
return null;
}
}

Private void btn_Select_Click (object sender, EventArgs e)
{
Try
{
MySqlconn=new MySqlConnection (@ "server=" + coB_Server. Text + "; Port="+ coB_Port. Text +"; The database=INFORMATION_SCHEMA; User="+ coB_sa. Text +"; Password="+ tB_PassWord. Text. The Trim ());
MySqlconn. The Open ();

If (MySqlconn. State==ConnectionState. Open)
Try
{
String STR="server=" + coB_Server. Text + "; The database=INFORMATION_SCHEMA; Uid="+ coB_sa. Text +"; The Pwd="+ tB_PassWord. Text +"; ";
CoB_DB. The DataSource=getTable (STR);
CoB_DB. DisplayMember="SCHEMA_NAME";
CoB_DB. ValueMember="SCHEMA_NAME";
}
The catch (Exception ex)
{
Throw the ex.
}
}
The catch (Exception ey)
{
Throw ey.
}
}

CodePudding user response:

The currently used to connect the user has sufficient permissions, directly in the MySQL database query execution, can also see to the corresponding database list,
The above script execution time, not an error, also not update the data, look for a long time, has not been able to find out the problem,
  •  Tags:  
  • C#
  • Related