In the following code it's only the subject code of English language that's being read by SQLDataReader dr, as indicated in line 4 of the code. When I replace "english" with "social" it's only the subject code of Social Studies that's accordingly read. How can I make the DataReader read the subject code of any subject regardless of whether the subject name contain white space or not such as Biology, English Language, Principles of Cost Accounting, etc, at any given time?
However, in the same line 4 when I replace "english" with ""& subname &"" only subject codes of subject names without white space is read by the DataReader. I would be more than grateful if someone could very kindly help me out.
Dim sql = "Select subjectCode From ProgramDetails.subjects where subjectname like @subname" Using con = New SqlConnection("Data Source=EBENEZERAKAGLO\SQLEXPRESS;Initial Catalog=Naass;Integrated Security=True") Using cmd = New SqlCommand(sql, con) cmd.Parameters.AddWithValue("@subname", String.Format("%{0}%", "english")) con.Open() Using rd = cmd.ExecuteReader() If rd.Read() Then Dim subjectCode = rd.GetInt32(0) subcode = subjectCode ' ... ' MsgBox(subjectCode) End If End Using End Using End Using
However, in the same line 4 when I replace "english" with ""& subname &"" only subject codes of subject names without white space is read by the DataReader. I would be more than grateful if someone could very kindly help me out.