Automation23
Member
- Joined
- Jul 13, 2022
- Messages
- 7
- Programming Experience
- 1-3
Hello! I am new to database testing. I am doing mobile automation and I need to validate sent data in the database. I am trying to write a method that will open the db connection, do some implementation, and then close it. I need a method to return a value but I am stuck with it.
So far I have this:
How can I return the first value of the first column from that query and then validate it with the expected output?
Another question, what is the best practical way/strategy to test the sent data in the database? Any advice?
Thank you in advance! Any help would be appreciated.
So far I have this:
C#:
public static int GetMemberId(string username){
using (SqlConnection connection = new SqlConnection(Config.connectionString)){
string query = $"select id from memberTable where username like '{username}'";
using (SqlCommand command = new SqlCommand(query, connection)){
connection.Open();
using (SqlDataReader reader = command.ExecuteReader()){
//not sure about the following line
int i = Int32.Parse(ExecuteQuery(query).Rows[0].ItemsArray[0].ToString());
//ExecuteQuery() method is a customed method that returns DataTable
}
}
}
}
How can I return the first value of the first column from that query and then validate it with the expected output?
Another question, what is the best practical way/strategy to test the sent data in the database? Any advice?
Thank you in advance! Any help would be appreciated.