Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the code i had written


private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ constring=L"datasourse=localhost;port=3306;username=root;password=password";

MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);<-(it display that the semicoloun with red line, the problem state that Argument Exception was unhandled, keyword not supported, Parameter name: datasource)

MySqlCommand^ cmdDataBase=gcnew MySqlCommand("select * from login_acc.login where Username='"+this->textBox1+"' and Password='"+this->textBox2->Text+"';",conDataBase);
MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader=cmdDataBase->ExecuteReader();
int count=0;
while(myReader->Read()){
count=count+1;

}
if(count==1){
MessageBox::Show("Login!");
}
else if(count>1){
MessageBox::Show("Fail");
}
else
MessageBox::Show("Pease check your usename and password.");
}catch(Exception^ex){
MessageBox::Show(ex->Message);
}
}

What I have tried:

I tried online searching but i can't find a solution
Posted
Updated 18-Oct-16 19:44pm

1 solution

That's because "datasource" is spelled with a "c":
C++
String^ constring=L"datasourse=localhost;port=3306;username=root;password=password";
                            ^
                            |

But don't hard-code connection strings, it means you have to change your code every time you release it. Which means re-testing it, and this time you are testing against the production database. Dangerous!

And a couple of other things:
1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
2) The name of a control is not the same as it's Text property: Your username will always be "System.Windows.Controls.Textbox"...
3) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] - it's in C# but it's all still applicable.
 
Share this answer
 
v2
Comments
Member 12801567 19-Oct-16 5:17am    
Thx for tips and advice, I'm just a beginner, i will improve it
OriginalGriff 19-Oct-16 5:27am    
We all have to start somewhere! :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900