title: Syntax error in query. Incomplete query clause in Max statement inside a function
body: <p>I am trying to simply connect to a database. But the problem arises in the concatenation part of the Sql query. </p>
  
  <p>When I do:</p>
  
  <pre><code> cmd = New OleDbCommand("Select max(ID) from Table1", con)
  </code></pre>
  
  <p>There is no error but when I do </p>
  
  <pre><code> cmd = New OleDbCommand("Select max(ID) from'" &amp; tablename &amp; "'", con)
  </code></pre>
  
  <p>The vb.net error comes: <strong>Syntax error in query. Incomplete query clause.</strong></p>
  
  <p>Here is the full code</p>
  
  <pre><code>Function Get_Max(ByVal Get_Table_Name As String)
      Dim tablename As String = Get_Table_Name
      Dim found_max As Integer
      Call connect()
      con.Open()
      cmd = New OleDbCommand("Select max(ID) from'" &amp; tablename &amp; "'", con)
      dr = cmd.ExecuteReader
      While dr.Read
          found_max = dr(0)
      End While
      con.Close()
      MsgBox(found_max)
  
      Return found_max
  
  End Function
  </code></pre>