簡體   English   中英

讀者僅從MySQL數據庫中選擇空字段-錯誤消息:值不能為NULL參數:項目

[英]Reader only select empty Fields from MySQL-Database - Error Message: The Value cannot be NULL Paramter: Item

如果嘗試從MySQL數據庫中選擇數據庫,則會收到錯誤消息:該值不能為NULL。 參數:item(德語:Der Wert darf nicht NULL sein。參數:item)因此,這意味着Reader僅選擇空字段-他“選擇NULL”-但是在我的SQL數據庫中這些字段沒有空。

private: void Fillcombo(void) {

String^ constring = L"datasource=localhost;port=3306;username=root;password=ichstinkenachmaggie";
MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand("select rank from database.ranks;", conDataBase);
MySqlDataReader^ myReader;

try {

    conDataBase->Open();
    myReader = cmdDataBase->ExecuteReader();
    while (myReader->Read()) {
        String^ vRank;
        myReader->GetString("rank");
        rank_combo->Items->Add(vRank);

    }

    }
catch (Exception^ex) {

    MessageBox::Show(ex->Message);

}

}

如果替換該行:

rank_combo->Items->Add(vRank);

有了這個:

rank_combo->Items->Add(vRank + "*****");

然后我沒有得到錯誤,但是在組合框中只有4行帶有5 ***** :(

您從未將變量vRank初始化為任何東西,當然它仍然為null。 您是否忘記將GetString的結果分配給vRank

while (myReader->Read()) {
    String^ vRank;
    vRank = myReader->GetString("rank");
    ^^^^^^^^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM