Exemplo n.º 1
0
        private async Task <DTReturnClass> AsyncDataTableMethods(string strQuery, SP_Parameters p, bool isProc)
        {
            DTReturnClass outcome = new DTReturnClass(true);
            DataTable     dt      = new DataTable();

            string errormsg = "";
            bool   isError  = false;

            using (var conn = new SqlConnection(connectionstring)) {
                await conn.OpenAsync();

                using (var command = new SqlCommand(strQuery, conn)) {
                    command.CommandTimeout = commandtimeout;
                    if (isProc)
                    {
                        command.CommandType = CommandType.StoredProcedure;
                    }
                    else
                    {
                        command.CommandType = CommandType.Text;
                    }

                    if (p != null)
                    {
                        foreach (SqlParameter objparam1 in p)
                        {
                            command.Parameters.Add(objparam1);
                        }
                    }

                    try {
                        using (SqlDataAdapter sda = new SqlDataAdapter(command)) {
                            sda.Fill(dt);
                        }
                    } catch (Exception ex) {
                        errormsg = ex.ToString();
                        isError  = true;
                    }
                }
            }


            if (isError)
            {
                outcome.Success     = false;
                outcome.Message     = "A query Failed. Please see logs for exact error";
                outcome.Techmessage = "GetDataTable error. Query is[" + strQuery + "] Error:[" + errormsg + "]";
            }
            else
            {
                if (dt != null)
                {
                    outcome.Datatable = dt;
                }
                else
                {
                    outcome.Success     = false;
                    outcome.Message     = "A query Failed. Please see logs for exact error";
                    outcome.Techmessage = "GetDataTable error. Datatable is null";
                }
            }

            return(outcome);
        }