title: Converting an int value to a string not working
body: <p>I have successfully created a timetable which displays the weekly classes for a student and staff member using session variables for each; StudentId and StaffId respectively. However I want to display a timetable for a module in the same way and so I have used a cascading dropdown list to allow the user to select a course first and then show the available modules by using onSelectedIndexChange (Fig.1) </p>
  
  <p>The dropdown list is called ddlModule and so when the user selects a module they are choosing a ModuleId. I want this value ddlModuleId to be then passed into the query which is defined in App_Code/DBAccess.cs shown in Fig.2.</p>
  
  <p>I have tried this string conversion but it throws an error. (Fig.3)</p>
  
  <pre><code>string module_ID = Convert.ToString(ddlModule.text); 
  </code></pre>
  
  <p>I have hardcoded </p>
  
  <pre><code>string Module_ID = "6"; 
  </code></pre>
  
  <p>to show how it should look when the module is selected</p>
  
  <p>Fig 1. - ddlModule_SelectedIndexChanged</p>
  
  <pre><code>protected void ddlModule_SelectedIndexChanged(object sender, EventArgs e)
          {
              ddlModule.Items.Clear();
  
              ddlModule.AppendDataBoundItems = true;
              String strConnString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
              String strQuery = "select ModuleId, ModuleCode from Module where CourseId=@CourseId";
              SqlConnection con = new SqlConnection(strConnString);
              SqlCommand cmd = new SqlCommand();
              cmd.Parameters.AddWithValue("@CourseId", ddlCourse.SelectedItem.Value);
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = strQuery;
              cmd.Connection = con;
              try
              {
                  con.Open();
                  ddlModule.DataSource = cmd.ExecuteReader();
                  ddlModule.DataTextField = "ModuleCode";
                  ddlModule.DataValueField = "ModuleId";
                  ddlModule.DataBind();
                  if (ddlModule.Items.Count &gt; 1)
                  {
                      ddlModule.Enabled = true;
                  }
                  else
                  {
                      ddlModule.Enabled = false;
  
                  }
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              finally
              {
                  con.Close();
                  con.Dispose();
              }
  
          }
  </code></pre>
  
  <p>Fig 2. - DBAccess.cs</p>
  
  <pre><code>  public String[] getModulesAtCurrentSlot(int timeslotInt, String moduleID, String Day)
          {
              List&lt;String&gt; modulesList = new List&lt;string&gt;();
              if (conn.State.ToString() == "Closed")
              {
                  conn.Open();
              }
              SqlCommand newCmd = conn.CreateCommand();
              newCmd.Connection = conn;
              newCmd.CommandType = CommandType.Text;
              newCmd.CommandText = "SELECT DISTINCT Module.ModuleCode,ClassType.ClassTypeName,Convert(time,Class.StartTime), Convert(time,Class.EndTime),Building.BuildingName,RoomCode.RoomCode,Class.Color" +
                                  " FROM Class INNER JOIN Module ON Class.ModuleId = Module.ModuleId INNER JOIN RoomCode ON Class.RoomCodeId = RoomCode.RoomcodeId INNER JOIN Building ON RoomCode.BuildingId = Building.BuildingId INNER JOIN Days ON Class.DayId = Days.DayID INNER JOIN ClassType ON Class.ClassTypeId = ClassType.ClassTypeId WHERE " +
                                  " Module.ModuleId = " + moduleID + " AND Convert(Date,StartTime) = '" + Day + "' AND ClassScheduleStartTimeId = " + timeslotInt.ToString();
              SqlDataReader dr = newCmd.ExecuteReader();
              while (dr.Read())
              {
                  //Module.ModuleCode,ClassType.ClassTypeName,Convert(time,Class.StartTime), Convert(time,Class.EndTime),Building.BuildingName,RoomCode.RoomCode,Class.Color
                  String current = "&lt;div class='slot'&gt;";
                  current += "&lt;div class='line1'&gt;" + dr.GetString(0) + "&amp;nbsp;" + dr.GetString(1) + "&lt;/div&gt;";// +"&lt;br /&gt;";
                  current += "&lt;div class='line2'&gt;" + dr.GetTimeSpan(2).ToString().TrimEnd('0').TrimEnd('0').TrimEnd(':') + "&amp;nbsp;-&amp;nbsp;" + dr.GetTimeSpan(3).ToString().TrimEnd('0').TrimEnd('0').TrimEnd(':') + "&lt;/div&gt;";// +"&lt;br /&gt;";
                  current += "&lt;div class='line3'&gt;" + dr.GetString(4) + "&amp;nbsp;" + dr.GetString(5) + "&lt;/div&gt;";
                  current += "&lt;/div&gt;";
                  modulesList.Add(current);
              }
              conn.Close();
              return modulesList.ToArray();
          }
  </code></pre>
  
  <p>Fig.3 - Error thrown
  <a href="https://i.stack.imgur.com/VYrXl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VYrXl.jpg" alt="enter image description here"></a></p>
  
  <p>Fig.4 - Using ModuleId = "6"</p>
  
  <p><a href="https://i.stack.imgur.com/CTcz1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CTcz1.png" alt="enter image description here"></a></p>
  
  <p>The error message is:</p>
  
  <pre><code>Incorrect syntax near '='.
  
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
  
  Source Error: 
  
  
  Line 117:                                " FROM Class INNER JOIN Module ON Class.ModuleId = Module.ModuleId INNER JOIN RoomCode ON Class.RoomCodeId = RoomCode.RoomcodeId INNER JOIN Building ON RoomCode.BuildingId = Building.BuildingId INNER JOIN Days ON Class.DayId = Days.DayID INNER JOIN ClassType ON Class.ClassTypeId = ClassType.ClassTypeId WHERE " +
  Line 118:                                " Module.ModuleId = " + moduleID + " AND Convert(Date,StartTime) = '" + Day + "' AND ClassScheduleStartTimeId = " + timeslotInt.ToString();
  Line 119:            SqlDataReader dr = newCmd.ExecuteReader();
  Line 120:            while (dr.Read())
  Line 121:            {
  
  Source File: c:\Users\40104198\Desktop\CIT\Qsis\DBAccess.cs    Line: 119 
  
  Stack Trace: 
  
  
  [SqlException (0x80131904): Incorrect syntax near '='.]
     System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2436598
     System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5731392
     System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +628
     System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady) +3731
     System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
     System.Data.SqlClient.SqlDataReader.get_MetaData() +89
     System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
     System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task, Boolean asyncWrite) +375
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
     System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
     System.Data.SqlClient.SqlCommand.ExecuteReader() +99
     Qsis.DBAccess.getModulesAtCurrentSlot(Int32 timeslotInt, String moduleID, String Day) in c:\Users\40104198\Desktop\CIT\Qsis\DBAccess.cs:119
     Qsis.Students.ModuleTimetable.Page_Load(Object sender, EventArgs e) in c:\Users\40104198\Desktop\CIT\Qsis\Students\ModuleTimetable.aspx.cs:140
     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
     System.Web.UI.Control.OnLoad(EventArgs e) +95
     System.Web.UI.Control.LoadRecursive() +59
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2952
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/hD7oX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hD7oX.jpg" alt="Debugging screenshot"></a></p>