How to Update specific row on Mysql Database based textfield input without using an ID in c#?


I have this database:
Database Image

The database in picture have only CASE_KEY and DEPARTMENT_CASE_NUMBER column, and it doesn’t have an ID. What I want to accomplish is to update my database using a TextField.Text without using ID but the problem is I don’t know what to put in my Sql Command WHERE clause, because the database doesn’t have an ID. Note I am not allowed to put an ID column. This is what I did so far. Please comment what are the alternatives I can use. Thank you.


     command.CommandText = "UPDATE TV_LABCASE SET DEPARTMENT_CASE_NUMBER = @departmentCaseNumber WHERE //This is my problem";
     command.Connection = connect;

     command.Parameters.AddWithValue("@departmentCaseNumber", txtDepartmentCase.Text);


if the CASE_KEY and the DEPARTMENT_CASE_NUMBER are unique together, that is your ID

You could do something like this:

 command.CommandText = "UPDATE TV_LABCASE SET DEPARTMENT_CASE_NUMBER = @newDepartmentCaseNumber WHERE CASE_KEY = @caseKey AND DEPARTMENT_CASE_NUMBER = @oldDepartmentCaseNumber";
 command.Connection = connect;

 command.Parameters.AddWithValue("@newDepartmentCaseNumber ", txtDepartmentCase.Text);
 command.Parameters.AddWithValue("@caseKey", variableThatContainsThisInfo);
 command.Parameters.AddWithValue("@oldDepartmentCaseNumber", variableThatContainsThisInfo);

Note that I did change the departmentCaseNumber into newDepartmentCaseNumber

Answered By – Camadas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published