I am trying to create a c# application which tries to connect and query the MySql Database. Below is the piece of code that I am using
public static void ValidateName(MySqlConnection conn,List<Employee> EmpList, string Group)
{
string selectQuery = "Select Name from Employee where Group = @Group AND @Name in (FirstName, LastName);";
using (MySqlCommand cmd = new MySqlCommand(selectQuery, conn))
cmd.Parameters.Add(new MySqlParameter("@Group", MySqlDbType.VarChar));
cmd.Parameters.Add(new MySqlParameter("@Name", MySqlDbType.VarChar));
for (int i = 0; i < EmpList.Count; i++)
{
cmd.Parameters["@Group"].Value = Group;
cmd.Parameters["@Name"].Value = EmpList[i].Name;
var reader = cmd.ExecuteReader();
List<string> lineList = new List<string>();
while (reader.Read())
{
lineList.Add(reader.GetString(0));
}
if (lineList.Count <=0)
{
WriteValidationFailure(EmpList[i], "Failed");
}}
It now throws error in the statement
var reader = cmd.ExecuteReader();