asp.net for循环连续执行sql语句做查询动作 在线等啊 ii是个数据集合 想放一条sql中执行sql 下面是代码 ii += VIPCard; ii += ","; } ii = ii.Replace("'", "");//导单把单引号替换成空格 string[] array = ii.Split('|'); string str = ""; for (int k = 0; k < array.Length ; k++) { string[] arr = array[k].Split(','); string sql1 = "select a.[Name],a.VIPCard, a.Tel,a.status,a.codedesc,sum(b.amt) as amt from customersendmsg a , lesmis.dbo.les_sale_detail b where a.VIPCard=b.vipcard and b.transdate='" + arr[0].ToString() + "' and b.transdate<='20120501' and b.vipcard='20120531' GROUP BY a.[Name],a.VIPCard, a.Tel,a.status,a.codedesc"; DataSet ds1 = new DataSet(); ds1 = MSSQL.GetDataSet(sql1, "SOA_gk"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string Name1 = ds.Tables[0].Rows[i][0].ToString().Trim(); string VIPCard = ds.Tables[0].Rows[i][1].ToString().Trim(); string Tel = ds.Tables[0].Rows[i][1].ToString().Trim(); string status = ds.Tables[0].Rows[i][1].ToString().Trim(); string codedesc = ds.Tables[0].Rows[i][1].ToString().Trim(); string amt = ds.Tables[0].Rows[i][1].ToString().Trim();
result += Name1 + "\t" + VIPCard + "\t" + Tel + "\t" + status + "\t" + codedesc + "\t" + amt + "\t" + "\n"; }
string sql1 = string.Empty;
for (int k = 0; k < array.Length; k++)
{
string[] arr = array[k].Split(',');
sql1 += "select a.[Name],a.VIPCard, a.Tel,a.status,a.codedesc,sum(b.amt) as amt from customersendmsg a , lesmis.dbo.les_sale_detail b where a.VIPCard=b.vipcard and b.transdate='" + arr[0].ToString() + "' and b.transdate<='20120501' and b.vipcard='20120531' GROUP BY a.[Name],a.VIPCard, a.Tel,a.status,a.codedesc ";
}
------解决方案-------------------- StringBuilder sb=new StringBuilder(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string Name1 = ds.Tables[0].Rows[i][0].ToString().Trim(); string VIPCard = ds.Tables[0].Rows[i][1].ToString().Trim(); string Tel = ds.Tables[0].Rows[i][1].ToString().Trim(); string status = ds.Tables[0].Rows[i][1].ToString().Trim(); string codedesc = ds.Tables[0].Rows[i][1].ToString().Trim(); string amt = ds.Tables[0].Rows[i][1].ToString().Trim();
sb.append(Name1 + "\t" + VIPCard + "\t" + Tel + "\t" + status + "\t" + codedesc + "\t" + amt + "\t" + "\n"); }
------解决方案--------------------