title: Making a normal method asynchronous in c#
body: <p>I have a method in c#:</p>
  
  <pre><code>public DataSet OpenSqlQuery(string SqlQuery)
  {
      con = new SqlConnection(connection_string);
      con.Open();
      var sqlc = new SqlCommand(SqlQuery, con);
      da = new SqlDataAdapter(sqlc);
      var ds = new DataSet();
      da.Fill(ds);
      con.Close();
      return ds;
  }
  </code></pre>
  
  <p>Now I want to make it as an asynchronous method so I can call it by <code>await</code>. so I changed it to:</p>
  
  <pre><code>public async Task&lt;DataSet&gt; OpenSqlQuery(string SqlQuery)
  {
      con = new SqlConnection(connection_string);
      con.Open();
      var sqlc = new SqlCommand(SqlQuery, con);
      da = new SqlDataAdapter(sqlc);
      var ds = new DataSet();
      await da.Fill(ds);
      con.Close();
      return ds;
  }
  </code></pre>
  
  <p>I set <code>await</code> before <code>da.Fill(ds)</code> because at this line, the program waits for server. But the function shows this error:</p>
  
  <blockquote>
    <p>'int' does not contain a definition for 'GetAwaiter' and no extension
    method 'GetAwaiter' accepting a first argument of type 'int' could be
    found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>How can I make this method asynchronous?</p>
  
  <p>P.S: The main goal is to call this method as follows:</p>
  
  <pre><code>Dataset ds = await objConnect.OpenSqlQuery(query);
  </code></pre>
  
  <p>P.S: Difference between this question and possible dupplicated one is that this post about making an existing synchronous method to asynchronous, while another is about making an asynchronous method.</p>