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.
CODE
connect.Open();
command.CommandText = "UPDATE TV_LABCASE SET DEPARTMENT_CASE_NUMBER = @departmentCaseNumber WHERE //This is my problem";
command.Connection = connect;
command.Parameters.AddWithValue("@departmentCaseNumber", txtDepartmentCase.Text);
command.ExecuteNonQuery();
CodePudding user response:
if the CASE_KEY
and the DEPARTMENT_CASE_NUMBER
are unique together, that is your ID
You could do something like this:
connect.Open();
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);
command.ExecuteNonQuery();
Note that I did change the departmentCaseNumber
into newDepartmentCaseNumber