I am trying to use SqlDataReader to check if a record exists. If it exists, it will return an identifier, otherwise it will return false. When I try to compile, I get the error message “Unable to convert the group of Reading methods to non-delegate type“ bool. ”I am following an example that I found in VB, but it seems that the translation may be incorrect.
private string checkProfileExists() { string strReturn = "False"; string strSql = ("SELECT ID FROM tblInformation WHERE txtUsername=@UserName " + "AND TrackingID=@TrackingID "); string strConn = ConfigurationManager.ConnectionStrings["WEM_PassWord_Reset"]. ConnectionString; SqlConnection objConn = new SqlConnection(strConn); SqlCommand objCmd = new SqlCommand(strSql, objConn); objCmd.Parameters.AddWithValue("@Username", txtUsername.Text); objCmd.Parameters.AddWithValue("@TrackingID", txtTrackingID.Text); try { objConn.Open(); System.Data.SqlClient.SqlDataReader rdr = objCmd.ExecuteReader(); if (rdr.Read) { strReturn = rdr("ID").ToString; } else { strReturn = "False"; } } catch (Exception ex) { lblErrorMessage.Text = ex.ToString(); } finally { objConn.Close(); objCmd = null; } return strReturn; }
Jason source share