ExecuteNonQuery / ExecuteScalar
Namespaces:
System.Data;
System.Xml;
System.Configuration;
// Clear out any test records from previous test executions.
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings[“DB_NAME”].ConnectionString))
{
connection.Open();
string _mediaId = string.Empty;
string _title = “Title”;
using (System.Data.SqlClient.SqlCommand cmd = connection.CreateCommand() as System.Data.SqlClient.SqlCommand)
{
System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand(sql, connection);
cmd1.CommandType = CommandType.Text;
using (System.Data.SqlClient.SqlDataReader reader = cmd1.ExecuteReader())
{
while (reader.Read())
{
_id = reader[“Id”].ToString() as string;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
//****************************
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
string _id = cmd.ExecuteScalar().ToString();
if (!string.IsNullOrEmpty(_id))
{
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
//**************************
}
reader.Close();
}
}
connection.Close();
}
Verifying if the text exists – Selenium WebDriver selected dropdownlist Text