[英]Reader only select empty Fields from MySQL-Database - Error Message: The Value cannot be NULL Paramter: Item
If I try to select the Database from a MySQL Database I get a Error Message: The Value can not be NULL. 如果尝试从MySQL数据库中选择数据库,则会收到错误消息:该值不能为NULL。 Paramter: item (In German its: Der Wert darf nicht NULL sein. Parameter: item) So that means the Reader only select empty fields - he "selects NULL" - but the fields arent empty in my SQL-Database.
参数: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);
}
}
If replace the line: 如果替换该行:
rank_combo->Items->Add(vRank);
with this: 有了这个:
rank_combo->Items->Add(vRank + "*****");
then I dont get the error but in the combobox there are only 4 lines with 5 ***** :( 然后我没有得到错误,但是在组合框中只有4行带有5 ***** :(
You never initialized the variable vRank
to anything, of course it's still null. 您从未将变量
vRank
初始化为任何东西,当然它仍然为null。 Did you forget to assign the result of GetString
to vRank
? 您是否忘记将
GetString
的结果分配给vRank
?
while (myReader->Read()) {
String^ vRank;
vRank = myReader->GetString("rank");
^^^^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.