oracle mysql 执行多次sql

var s = @"Data Source=AFP_USER;Persist Security Info=True;User ID=afp_user;Password=user_afp;Unicode=True";
            var c = new OracleConnection(s);
            c.Open();
            string sql1 = @"select  ad.id,ad.name,asmb.MEDIA_BUY_ID,asmb.SHARE_PERCENTAGE from  ad_space ad join ad_space_media_buy asmb on ad.ID=asmb.AD_SPACE_ID where asmb.AD_SPACE_ID in (52441)";

            string sql2 = @"select ad.id,ad.name,amb.media_buy_id,amb.SHARE_PERCENTAGE from ad_space ad join ad_space_media_buy  amb on ad.ID=amb.AD_SPACE_ID where ad.ID in (" + aids + @")";

            var qc = new OracleCommand(sql1, c);
            var wc = new OracleCommand(sql2, c);
            try
            {
                var dr = qc.ExecuteReader();
                while (dr.Read())
                {
                    var adspace = new Adspace
                    {
                        AdspaceId = Convert.ToInt32(dr["ad_space_id"] is DBNull ? 0 : dr["ad_space_id"]),
                        Name = dr["aname"].ToString(),

                    };
                    var am = new AdspaceMediabuy
                    {
                        AdspaceId = Convert.ToInt32(dr["ad_space_id"] is DBNull ? 0 : dr["ad_space_id"]),
                        MediabuyId = Convert.ToInt32(dr["media_buy_id"] is DBNull ? 0 : dr["media_buy_id"]),
                        SharePercentage = Convert.ToInt32(dr["share_percentage"] is DBNull ? 0 : dr["share_percentage"]),

                    };
                    adlist.Add(adspace);
                    amlist.Add(am);
                }
                var dr2 = wc.ExecuteReader();
                while (dr2.Read())
                {
                    var mediabuy = new Mediabuy
                    {
                        AdvFeature = Convert.ToInt32(dr2["adv_feature"] is DBNull ? 0 : dr2["adv_feature"]),
                        Budget = Convert.ToInt64(dr2["budget"] is DBNull ? 0 : dr2["budget"]),
                        CampaignId = Convert.ToInt32(dr2["campaign_id"] is DBNull ? 0 : dr2["campaign_id"]),
                        CampaignName = dr2["campaign_name"].ToString(),
                        ChargeType = (AdChina.Publisher.AdServer.Models.Enumerations.ChargeType)Convert.ToInt16(dr2["charge_type"]),
                        Priority = AdChina.Publisher.AdServer.Common.TryParse.GetInt32(dr2["priority"]),
                        SpecificBuy = Convert.ToInt32(dr2["specific_buy"] is DBNull ? "0" : dr2["specific_buy"]),
                        GeoLocation = dr2["geo_location"].ToString(),
                        MediaubyId = Convert.ToInt32(dr2["media_buy_id"] is DBNull ? "0" : dr2["media_buy_id"]),
                        DailyBudget = Convert.ToInt32(dr2["daily_budget"] is DBNull ? "0" : dr2["daily_budget"]),
                        MediabuyName = dr2["mname"].ToString(),
                    };

                }
                dr.Close();
               dr2.Close();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {

                c.Close();
            }
下面是mySql:

var s = "Database=afp;Data Source=192.168.28.120;Port=3306;User Id=root;Password=27510501";


            var c = new MySqlConnection(s);

            c.Open();
            var q = "select id,name from ad_space where status>0";
            var w = "select id,name from media_buy where status>0";

            var qc = new MySqlCommand(q, c);
            var wc = new MySqlCommand(w, c);
            try
            {
                var r = qc.ExecuteReader();
                while (r.Read())
                {
                    Console.WriteLine(r["id"].ToString());
                }
                c.Close();
                c.Open();

                var r2 = wc.ExecuteReader();

                while (r2.Read())
                {
                    Console.WriteLine(r2["id"].ToString());
                }
                r.Close();
                r2.Close();
            }
            catch (Exception)
            {
                
                throw;
            }
            finally
            {
                
                c.Close();
            }

转载于:https://www.cnblogs.com/chenru1988/archive/2012/08/28/2660430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值