hi, i am trying to retrieve some data from mysql(c#,mono), the problem is that if the returned value is null the program crashes, i know it has to do something with the returned null value, because if i want to retrieve something that is in the database it works,can anyone help me with this?
The code:
MySqlConnection dbcon;
dbcon = new MySqlConnection(conString);
try
{
dbcon.Open();
}
catch (Exception)
{
Console.WriteLine("MySQL Database Connection Problem !!!");
}
//reading data from mysql
MySqlCommand dbcmd = new MySqlCommand(sql, dbcon);
MySqlDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()){
txtFirstname.Text = reader["first_name"].ToString();
txtLastname.Text = reader["last_name"].ToString();
imgUser.File = path+reader["photo"].ToString();
expDate = reader["expiration_datetime"].ToString();
usrName = reader["username"].ToString();
}
dbcon.Close();