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();
}