Can someone explain why this is happening? I am trying to retrieve data from mysql database but this error occur but the same code works fine when I retrieve a integer value such as TeacherID. Something is wrong with retraveling non-numeric values.
string connectionString = (@"Data Source=(LocalDB)\v11.0;AttachDbFilename=\myDB.mdf;Integrated Security=True");
string sql = "SELECT * FROM Teacher WHERE Subject = "+ TSubject.Text;
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Teacher");
connection.Close();
DataGridViewStudent.DataSource = ds;
DataGridViewStudent.DataMember = "Teacher";
I have already checked spell mistake or type, all okay. So what is the issue?