title: problem with getting data from database
body: <p>I am trying to get the  data from database by using the below code.....</p>
  
  <p>if there is no data in the table it will always goes to 
  this statement</p>
  
  <p>I am using mysql.net connector for getting the data and i am doing winforms  applications
  using c#</p>
  
  <pre><code>     public DataTable sales(DateTime startdate, DateTime enddate)
       {
           const string sql = @"SELECT memberAccTran_Source as Category, sum(memberAccTran_Value) as Value
                                FROM memberacctrans
                                WHERE memberAccTran_DateTime BETWEEN @startdate AND @enddate
                                GROUP BY memberAccTran_Source";
  
           return sqlexecution(startdate, enddate, sql);
       }
  </code></pre>
  
  <p>and the below code is for return sqlexceution...function..</p>
  
  <pre><code> private static DataTable sqlexecution(DateTime startdate, DateTime enddate, string sql)
   {
           var table = new DataTable();
           using (var conn = new MySql.Data.MySqlClient.MySqlConnection(connectionstring))
           {
               conn.Open();
  
               var cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, conn);
  
               var ds = new DataSet();
  
               var parameter = new MySql.Data.MySqlClient.MySqlParameter("@startdate", MySql.Data.MySqlClient.MySqlDbType.DateTime);
               parameter.Direction = ParameterDirection.Input;
               parameter.Value = startdate.ToString(dateformat);
               cmd.Parameters.Add(parameter);
  
               var parameter2 = new MySql.Data.MySqlClient.MySqlParameter("@enddate", MySql.Data.MySqlClient.MySqlDbType.DateTime);
               parameter2.Direction = ParameterDirection.Input;
               parameter2.Value = enddate.ToString(dateformat);
               cmd.Parameters.Add(parameter2);
  
               var da = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd);
  
               da.Fill(ds);
               try
               {
                   table = ds.Tables[0];
  
               }
               catch
               {
                   table = null;
               }
           }
           return table;
       }
  </code></pre>
  
  <p>even if there is no data the process flow will goes to this line </p>
  
  <blockquote>
    <p>table = ds.Tables[0];</p>
  </blockquote>
  
  <p>how can i reduce this .....</p>
  
  <p>would any one pls help on this....</p>