Click here to Skip to main content
15,890,897 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# to Mysql Login code Error Pin
N Mohamed rafi22-Mar-22 1:46
N Mohamed rafi22-Mar-22 1:46 
GeneralRe: C# to Mysql Login code Error Pin
Dave Kreskowiak22-Mar-22 1:49
mveDave Kreskowiak22-Mar-22 1:49 
QuestionC# - managing JSON serialisation Pin
DerekT-P21-Mar-22 0:32
professionalDerekT-P21-Mar-22 0:32 
AnswerRe: C# - managing JSON serialisation Pin
Richard Deeming21-Mar-22 2:10
mveRichard Deeming21-Mar-22 2:10 
GeneralRe: C# - managing JSON serialisation Pin
DerekT-P21-Mar-22 3:21
professionalDerekT-P21-Mar-22 3:21 
GeneralRe: C# - managing JSON serialisation Pin
Richard Deeming21-Mar-22 3:28
mveRichard Deeming21-Mar-22 3:28 
AnswerRe: C# - managing JSON serialisation Pin
Gerry Schmitz21-Mar-22 4:59
mveGerry Schmitz21-Mar-22 4:59 
GeneralRe: C# - managing JSON serialisation Pin
DerekT-P21-Mar-22 7:26
professionalDerekT-P21-Mar-22 7:26 
AnswerRe: C# - managing JSON serialisation Pin
Eddy Vluggen21-Mar-22 7:02
professionalEddy Vluggen21-Mar-22 7:02 
GeneralRe: C# - managing JSON serialisation Pin
DerekT-P21-Mar-22 7:34
professionalDerekT-P21-Mar-22 7:34 
QuestionRe: C# - managing JSON serialisation Pin
Eddy Vluggen21-Mar-22 12:26
professionalEddy Vluggen21-Mar-22 12:26 
QuestionNeed C# and Mysql Tutorial Pin
N Mohamed rafi20-Mar-22 18:13
N Mohamed rafi20-Mar-22 18:13 
AnswerRe: Need C# and Mysql Tutorial Pin
OriginalGriff20-Mar-22 20:43
mveOriginalGriff20-Mar-22 20:43 
AnswerRe: Need C# and Mysql Tutorial Pin
RobertSF21-Mar-22 10:29
professionalRobertSF21-Mar-22 10:29 
GeneralMysql Update Query Error Pin
N Mohamed rafi20-Mar-22 5:25
N Mohamed rafi20-Mar-22 5:25 
GeneralRe: Mysql Update Query Error Pin
Victor Nijegorodov20-Mar-22 7:47
Victor Nijegorodov20-Mar-22 7:47 
GeneralRe: Mysql Update Query Error Pin
N Mohamed rafi20-Mar-22 8:44
N Mohamed rafi20-Mar-22 8:44 
SuggestionRe: Mysql Update Query Error Pin
Eddy Vluggen20-Mar-22 8:40
professionalEddy Vluggen20-Mar-22 8:40 
GeneralRe: Mysql Update Query Error Pin
N Mohamed rafi20-Mar-22 8:45
N Mohamed rafi20-Mar-22 8:45 
GeneralRe: Mysql Update Query Error Pin
OriginalGriff20-Mar-22 8:47
mveOriginalGriff20-Mar-22 8:47 
GeneralRe: Mysql Update Query Error Pin
Eddy Vluggen20-Mar-22 9:43
professionalEddy Vluggen20-Mar-22 9:43 
GeneralRe: Mysql Update Query Error Pin
OriginalGriff20-Mar-22 9:46
mveOriginalGriff20-Mar-22 9:46 
GeneralRe: Mysql Update Query Error Pin
Eddy Vluggen21-Mar-22 7:06
professionalEddy Vluggen21-Mar-22 7:06 
GeneralRe: Mysql Update Query Error Pin
OriginalGriff21-Mar-22 7:34
mveOriginalGriff21-Mar-22 7:34 
GeneralRe: Mysql Update Query Error Pin
Dave Kreskowiak20-Mar-22 10:49
mveDave Kreskowiak20-Mar-22 10:49 
So, it's obvious you're just copying and pasting code from the web and hoping it works. You don't have any idea why there are parameter objects or how they are used in the query.
C#
string query = "update employee set employee_id='" + this.textBox6.Text + "',employee_name='" + this.textBox7.Text + "',employee_salary='" + this.textBox8.Text + "' where employee_id='" + this.textBox6.Text + "';";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@employee_id", id);
cmd.Parameters.AddWithValue("@employee_name", name);
cmd.Parameters.AddWithValue("@employee_salary", salary);

You're using the TextBox values directly in your query. NEVER DO THIS! User input should be treated like it's the spawn of Satan. Using it directly in your query will lead to SQL Injection Attacks and you risk destroying your database doing that.

Next, you NEVER change or update the value of an ID field in a table. Doing so will destroy your data integrity since records in one table will no longer relate to data in another table.

Your query should look like this (and don't even think of copying and pasting this code!) Try to figure out what the code is doing.
C#
string query = "UPDATE employee SET employee_name=@empName, employee_salary=@empSalary WHERE employee_id=@empId";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@empId", id);
cmd.Parameters.AddWithValue("@empName", name);
cmd.Parameters.AddWithValue("@empSalary", salary);

I'm ignoring that you're storing salary values as text.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.