Jeppe Christensen Jeppe Christensen - 10 days ago 4x
ASP.NET (C#) Question

ExecuteReader() Object cant be converted

I have set up a mySql database on a server, and now i want to reach it in order for me to make a webservice. Firstly i just want to test if i can grab an entity from my query in my method (OneEntity), and put it into my list.

public IEnumerable<Person> Get()
return new List<Person> {
new Person{ ID = 0, First = OneEntity(), Last ="Example"}

public string OneEntity()
MySql.Data.MySqlClient.MySqlConnection mySqlConnection;
MySql.Data.MySqlClient.MySqlCommand cmd;
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["MySql"].ToString();
mySqlConnection = new MySql.Data.MySqlClient.MySqlConnection(connString);
cmd = new MySql.Data.MySqlClient.MySqlCommand();

cmd.CommandText = "SELECT 'name' FROM 'CustomerDb' WHERE 'id' = 0";
cmd.CommandType = CommandType.Text;
cmd.Connection = mySqlConnection;

SqlDataReader reader = cmd.ExecuteReader();
return reader;

I am not very experienced in c# and are therefore not sure if im doing it correct. However in my cmd.ExecuteReader() (Object i guess it is?!??!) i get that it

cannot implicitly convert type 'MySql.Data.MySqlDataReader' to

What am i doing wrong here?? obviously my return is not correct either, as i specified my method to be 'string'.. but even though i type in a string, the error doesn't dissapear?

MySqlDataReader Reader = cmd.ExecuteReader();

Use this line.