vendredi 27 février 2015

How to save the maximal value of a column of a MYSQL in a Integer [C++]

I have a problem. First of all I have to say that im kinda new into coding and especially into coding with C++. So I have this code here:



String^ constring = L"datasource=localhost;port=3306;username=root;password=ichstinkenachmaggie";
MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
MySqlCommand^ cmdID = gcnew MySqlCommand("select max(idUserInfo) from database.userinfo;", conDataBase);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand("insert into database.userinfo (idUserInfo,Username,Rank,Password) values('" + this->idUserInfo_txt->Text + "', '" + this->Username_txt->Text + "', '" + this->Password_txt->Text + "', '" + this->Rank_txt->Text + "');", conDataBase);
MySqlDataReader^ myReader;
MySqlDataReader^ idReader;

if (Password_txt->Text == confirmPassword_txt->Text) {

try{

if (idUserInfo_txt->Text == "0")
{
conDataBase->Open();
idReader = cmdID->ExecuteReader();
int i = idReader->getInt32;
i = i + 1;
idUserInfo_txt->Text = Convert::ToString(i);
myReader = cmdDataBase->ExecuteReader();
MessageBox::Show("Saved");

while (myReader->Read()) {

}


}
else {

conDataBase->Open();
myReader = cmdDataBase->ExecuteReader();
MessageBox::Show("Saved");

while (myReader->Read()) {

}

}



}
catch (Exception^ex) {

MessageBox::Show(ex->Message);

}
}
else MessageBox::Show("Passwords doesn't match!");
}


So I want to save the maximal Value of the column idUserInfo in the Integer i. My question: How do I do that or what do i have to change/add?


Thanks for your help! (and sry for my bad English :D)


Aucun commentaire:

Enregistrer un commentaire