|
How to change code in my coding like this sir?
because my code is logging in if i enter wrong username and password also
|
|
|
|
|
Put the same code in my code that why i can understand easily sir
|
|
|
|
|
 I have changed my code sir, but still logging in for wrong userid and password
if (textBox9.Text != "" && textBox10.Text != "")
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
string id = textBox9.Text;
string password = textBox10.Text;
textBox9.Text = "";
textBox10.Text = "";
string query = "select * from login where userid=@userid and password=@password";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@userid", id);
cmd.Parameters.AddWithValue("@password", password);
cmd.Connection = cnn;
cnn.Open();
cmd.ExecuteNonQuery();
DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation Message", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
MessageBox.Show("Login Successfully");
cnn.Close();
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
}
else if (dr == DialogResult.No)
{
MessageBox.Show("Please Enter Correct Login details");
}
}
}
else
{
MessageBox.Show("Please Enter With Correct Login Details");
}
|
|
|
|
|
There really is no point in continuing this thread. It does not matter how many times we tell you how to correct your code you insist on ignoring our advice. My previous reply showed you exactly how to do it correctly, and yet you just repeat the same bad code. I suggest you consider a different career path.
|
|
|
|
|
Why you are not correcting my code and sending me? i said the error you know the code and sending some examples also then you can send correct code it is useful to me please
|
|
|
|
|
|
Sir, How to write mysql query if stored userid password is correct means then it enter successfull suppose not stored values entered means the messagebox is wrong.....
|
|
|
|
|
Why do you ignore everything we tell you? Go back to the code sample I gave you, it shows exactly how to do it correctly. This is my last message on this subject.
|
|
|
|
|
Pls correct and send me in my code sir that why i can understand sir send me please
|
|
|
|
|
How many times do you have to be told "nobody is going to do your work for you" before it sinks in?
|
|
|
|
|
And you are still not checking the result of ExecuteNonQuery , but putting the success message based on the user pressing the "Yes" button.
|
|
|
|
|
How to check it. Please give step procedure sir or video link
|
|
|
|
|
I have already explained more than once. When you call cmd.ExecuteNonQuery(); you must check the return value, to see whether the SQL command succeeded. Only when you have a success return can you post a message that tells the user that his action has worked. You must do this on all database access commands, never assume that your code has worked - most of the time it has not.
|
|
|
|
|
No sir mysql command was not succeeded, when i am giving wrong userid passwor dit shows login successfull i think sql query to be change
|
|
|
|
|
Yes, it shows login successful because, as I keep repeating, you post that message even when the ExecuteNonQuery fails. You need to start thinking about your code in logical steps rather than just throwing statements together and hoping it will work.
1. Perform the ExecuteNonQuery , and capture the return value.
2. Does the return value indicate success?
2.1. No - tell the user it failed.
2.2 Yes - and only at this point, tell the user it succeeded.
3. Perform other actions.
|
|
|
|
|
I clearly telling again mysql query is error here, ExecuteNonQuery is returned value it means i logged in with wrong userid and password also.
|
|
|
|
|
No, that is not what it means, please read the documentation: SqlCommand.ExecuteNonQuery Method (System.Data.SqlClient) | Microsoft Docs[^]. When you use a SELECT to find a particular user id and the return value says that there is an existing row it means that the details are correct.
However since most of your code is in the wrong order it is unlikely that any of your results are correct.
|
|
|
|
|
Sir, You all are blaming me always, you know the code but you are not providing me. Thank you all.
|
|
|
|
|
I am so glad I didn't answer this question last night.
You're not trying to think about the problem. You're not trying to read the documentation on the methods you're calling. You're not trying to read the links other people have given you to educate you on what you should be doing. You're not trying to work out what you should be doing, logically, step-by-step. You're not trying to understand anything.
What you ARE trying to do, throughout this entire thread, is get other people to write your code for you, and that will teach you nothing.
|
|
|
|
|
Sir, Now you give the right code or not?
|
|
|
|
|
See, you're STILL trying to get other people to do your work for you.
The answer to that very question, from EVERYONE, is going to be NO. The only code you get is the code YOU write.
|
|
|
|
|
Waste of time in this forum. Bye
|
|
|
|
|
It's a waste of time only because YOU made it that way by begging other people to write your code for you.
|
|
|
|
|
I have a multi-layer application (user interface, business objects, data access layers). The business objects are inter-related as you might expect, so a "Group" has a property that returns an array of "Users", and each User may have multiple "Events" and each Event can have multiple "Locations" for example. Ultimately the data is accessible via a website which makes extensive use of webservices to load data dynamically. All is well and good and when a webservice loads an Event it gets all that event's Locations returned in the auto-generated JSON. When the webservice returns a Group object it also returns the list of Users, and for each User all their Events, and for each Event all the Locations. Which very quickly gets unwieldy! Not only does it make the webservice response very large, but the database is hit very hard (most of the properties are "lazy loading" so, in the rest of the application, a group's Users are loaded only when explicitly referenced, but the JSON serialization accesses ALL the properties of Group, so...)
I can control this to an extent by decorating some properties with [ScriptIgnore] (which I had to do to break some circular references; e.g. the User object has a reference to its owning Group).
However what I really need is a way to customise which properties are included depending on the context. For some webservices, all I need is the top-level object (e.g. Group), but for others I need all the Users in that group as well. Sometimes I only need a small subset of the properties of Group.
I've looked at creating very simple classes that contain just the items I need, and creating a property in the main class that populates and returns that simple class, but that seems like a lot of effort for each use case. Is there any way to use custom attributes on the properties such that I can specify an attribute name at run time and have the serializer include only matching properties?
|
|
|
|
|
You can't change attributes at run-time; they're compiled into the assembly.
You can either create custom DTOs, use anonymous types, or create one or more custom JSON converters.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|