简体   繁体   English

Visual C ++如何在MySql中查找列名

[英]Visual C++ how to find name of a column in MySql

I am currently using the following code to fill a combo box with the column information inside of MySql database: 我目前正在使用以下代码在MySql数据库中使用列信息填充组合框:

private: void Fillcombo1(void){
              String^ constring=L"datasource=localhost;port=3307;username=root;password=root";
              MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
              MySqlCommand^ cmdDataBase= gcnew MySqlCommand("select * from database.combinations ;", conDataBase);
              MySqlDataReader^ myReader;

              try{
              conDataBase->Open();
              myReader=cmdDataBase->ExecuteReader();
              while(myReader->Read()){
                String^ vName;
                vName= myReader->GetString("OD");
                comboBox1->Items->Add(vName);
              }
              }catch(Exception^ex){
              MessageBox::Show(ex->Message);
              }
             }

Is there any simple method for finding the name of the column and placing it within a combo box? 有没有简单的方法来查找列的名称并将其放置在组合框中?

Also, I am adding small details to my app such as a news feed which would need updating every so often, will I have to dedicate a full new database spreadsheet to this single news feed text so that I can updated it or is there a simpler alternative? 另外,我在我的应用程序中添加了一些小细节,例如新闻提要,它需要经常进行更新,我是否必须将一个全新的数据库电子表格专用于此单个新闻提要文本,以便我可以对其进行更新,或者是否更简单?另类?

Thanks. 谢谢。

There may be an easier way without launching any other query but you could also use "SHOW COLUMNS" MySQL Query. 可能有一种更简单的方法而无需启动任何其他查询,但是您也可以使用“ SHOW COLUMNS” MySQL查询。

SHOW COLUMNS FROM combinations FROM database

or 要么

SHOW COLUMNS FROM database.combinatons

Both will work. 两者都会起作用。

An alternative is to use the DESCRIBE statement: 一种替代方法是使用DESCRIBE语句:

mysql> describe rcp_categories;
+---------------+------------------+------+-----+---------+----------------+
| Field         | Type             | Null | Key | Default | Extra          |
+---------------+------------------+------+-----+---------+----------------+
| ID_Category   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| Category_Text | varchar(32)      | NO   | UNI | NULL    |                |
+---------------+------------------+------+-----+---------+----------------+
2 rows in set (0.20 sec)  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM