コード例 #1
0
ファイル: ChallanType.cs プロジェクト: sauravdebp/AE-Manager
        public static async Task<List<ChallanType>> RetrieveAllChallanTypes()
        {
            List<ChallanType> typeList = new List<ChallanType>();
            string sqlCmdString = "Select * From dbo.challan_types";
            Database myDb = new Database();
            SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection);
            SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlCmd);
            DataTable table = new DataTable();
            ChallanType challanType = null;

            await Task.Run(() =>
            {
                try
                {
                    myDb.OpenConnection();
                    sqlAdapt.Fill(table);

                    foreach (DataRow row in table.Rows)
                    {
                        challanType = new ChallanType()
                        {
                            TypeName = (String)row["type_name"],
                            IsPersist = true
                        };
                        typeList.Add(challanType);
                    }
                }
                finally
                {
                    sqlAdapt.Dispose();
                    table.Dispose();
                    myDb.CloseConnection();
                }
            });
            
            return typeList;
        }
コード例 #2
0
        public static async Task <List <ChallanType> > RetrieveAllChallanTypes()
        {
            List <ChallanType> typeList     = new List <ChallanType>();
            string             sqlCmdString = "Select * From dbo.challan_types";
            Database           myDb         = new Database();
            SqlCommand         sqlCmd       = new SqlCommand(sqlCmdString, myDb.Connection);
            SqlDataAdapter     sqlAdapt     = new SqlDataAdapter(sqlCmd);
            DataTable          table        = new DataTable();
            ChallanType        challanType  = null;

            await Task.Run(() =>
            {
                try
                {
                    myDb.OpenConnection();
                    sqlAdapt.Fill(table);

                    foreach (DataRow row in table.Rows)
                    {
                        challanType = new ChallanType()
                        {
                            TypeName  = (String)row["type_name"],
                            IsPersist = true
                        };
                        typeList.Add(challanType);
                    }
                }
                finally
                {
                    sqlAdapt.Dispose();
                    table.Dispose();
                    myDb.CloseConnection();
                }
            });

            return(typeList);
        }