Automation23
Member
- Joined
- Jul 13, 2022
- Messages
- 7
- Programming Experience
- 1-3
Hello! I have a method that retrieves the first value of the first row in the first column from the database. Now I need to assert if it's a null value or not. In the database the value is NULL. Even if I assert is if it doesn't equal to null and then make it true. The code is passing. Here is what I have so far:
The question is, how null values are stored in the database? I tried with the String.Empty but it still represents an empty value, so I don't think it's the right thing. How can I handle null values in the database in the c# assertions?
C#:
public static void TestAppointmentIsCancelled(int apptId)
{
using (SqlConnection connection = new SqlConnection(Config.connectionStringBH))
{
connection.Open();
string query = $"select CancellationTypeId, * from hcAppointments where appointmentId = '{apptId}'";
SqlCommand command = new SqlCommand(query, connection);
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Assert.IsTrue(reader.GetValue(0) != null);
}
}
}
}
The question is, how null values are stored in the database? I tried with the String.Empty but it still represents an empty value, so I don't think it's the right thing. How can I handle null values in the database in the c# assertions?