日期:2014-05-17 浏览次数:20477 次
string[] groupSub = groupList.Split(','); sql = string.Empty; for (int i = 0; i < groupSub.Length; i++) { sql = "select id,user_truename from l_user where id='" + Convert.ToInt32(groupSub[i].ToString()) + "'"; //有问题 table = DbHelperSQL.Query(sql).Tables[0]; dlSelectUser.DataSource = table; dlSelectUser.DataBind(); }
string[] groupSub = groupList.Split(','); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < groupSub.Length; i++) { int n = 0; if (int.TryParse(groupSub[i], out n)) { sb.Append(groupSub[i] + ","); } } if (sb.Length > 0) { sb.Remove(sb.Length - 1, 1); sql = "select id,user_truename from l_user where id IN(" + sb.Length() + ")"; table = DbHelperSQL.Query(sql).Tables[0]; dlSelectUser.DataSource = table; dlSelectUser.DataBind(); }
------解决方案--------------------
dlSelectUser.DataSource = table;
dlSelectUser.DataBind();
放在循环外面
------解决方案--------------------
string[] groupSub = groupList.Split(','); sql = string.Empty; DataTable table =new DataTable(); for (int i = 0; i < groupSub.Length; i++) { sql = "select id,user_truename from l_user where id='" + groupSub[i].ToString() + "'"; //有问题 table = DbHelperSQL.Query(sql).Tables[0]; ListItem lt = new ListItem(); lt.Text = table.Rows[0]["user_truename"].ToString(); lt.id = table.Rows[0]["id"].ToString(); dlSelectUser.Items.Add(lt); } dlSelectUser.DataBind(); ---这样做要和数据访问 好多次! 建议, select id,user_truename from l_user where id IN() 一次读出!在绑定!
------解决方案--------------------
string[] groupSub = groupList.Split(','); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < groupSub.Length; i++) { int n = 0; if (int.TryParse(groupSub[i], out n)) { sb.Append(groupSub[i] + ","); } } if (sb.Length > 0) { sb.Remove(sb.Length - 1, 1); sql = "select id,user_truename from l_user where id IN(" + sb.Length() + ")"; table = DbHelperSQL.Query(sql).Tables[0]; dlSelectUser.DataSource = table; dlSelectUser.DataBind(); } 这个是一次,读出,直接绑定就行了!
------解决方案--------------------
学习中
------解决方案--------------------