Resolved How to check multiple values in one record

PDS8475

Active member
Joined
Jun 25, 2019
Messages
41
Programming Experience
Beginner
HI
I am trying to check if a specific record exists in the database.
I am Using the following code
C#:
OleDbCommand check_All = new OleDbCommand("SELECT COUNT(*) FROM Donations WHERE EquipmentType = @TestType AND EquipmentMake = @TestMake AND EquipmentModel = @TestModel AND EquipmentSerial = @TestSerial", Testconnection);
                        check_All.Parameters.AddWithValue("@TestType", Type_comboBox.Text);
                        check_All.Parameters.AddWithValue("@TestMake", Make_textBox.Text);
                        check_All.Parameters.AddWithValue("@TestModel", Model_textBox.Text);
                        check_All.Parameters.AddWithValue("@TestSerial", Serial_textBox.Text);
                        //Testconnection.Open();
                        int AllExist = (int)check_Serial.ExecuteScalar();
                        if (AllExist > 0)
                        {
                            MessageBox.Show("All exists");
                        }
                        else
                        {
                            MessageBox.Show("All does not exist");
                        }

The problem is that it checks that the values are anywhere in the database but not if they are in the same record. How would I go about checking that they are all in the same record?
 
I don't understand. The way your query is written, you are already checking if all those values are on a record. What problem are you encountering?
 
Lets first look at what your statement is doing.
The COUNT (*) function returns the number of rows that exist relative to your WHERE clause of your SELECT statement. COUNT(*) will only return the integral number of records and not the actual records contained within in your WHERE clause.

So what do you think you need to do?
 
Also, if you are going to mark your thread as resolved, you should at least provide the solution to the problem at hand...
 
Back
Top Bottom