Sukhomlin Eugene Sukhomlin Eugene - 2 months ago 58x
MySQL Question

Search in Database from UWP (C#)

I try to make search in database from UWP app for Windows 10

My code

using (MySqlConnection connection = new MySqlConnection("Database= milanoold_db;Data Source=;User Id=milanoold_u;Password=sK5PvCDP; SslMode=None; CharSet=utf8"))


MySqlCommand createCommand = new MySqlCommand("SELECT * FROM reg_user WHERE mob LIKE N'%+380675090373%'", connection);
EncodingProvider ppp;
ppp = CodePagesEncodingProvider.Instance;
MySqlDataReader reader = createCommand.ExecuteReader();


But I have this in console.


What's wrong with my code.

I need that it show row like this



A data reader is a object representation of your result set. Calling ToString() on most class will only return the name of the class, unless it has a logical string representation of it's value (int for example) (I believe this is the default behavior if not overwritten). To read the data from a data reader you have to loop trough the rows and cells. See this link for an example. To keep it simple, you call While (Read()) to see if there is more data then read cell by cell the data you want.

PS.: If you are only expecting one value (one row, one cell), you can also use the ExecuteScalar of the MySqlCommand.