日期:2014-05-17  浏览次数:20491 次

怎么实现这样的字符串连接?
DataTable dt = HcPBCommBLL.GetHcPBGroupCatalogID(hashtable)

我有一数据表(dt)读出来的数据如下:

row catalog_id

1 41
2 21
3 55
4 33

怎么把列catalog_id的数据连接成 string id="41,21,55,33"

谢谢

------解决方案--------------------
String id=""
for (int i=0;i<=dt.Rows.count-1;i++
{
id=id & dt.Row[i][1] & ",";
}
id=id.TrimEnd(",");
------解决方案--------------------
C# code

DataTable dt = new DataTable("image");
        DataColumn dc1, dc2;
        dc1 = new DataColumn("row", System.Type.GetType("System.Int32"));
        dc1.AutoIncrement = true;
        dc1.AutoIncrementSeed = 1;
        dc1.AutoIncrementStep = 1;
        dt.Columns.Add(dc1);

        dc2 = new DataColumn("catalog_id", System.Type.GetType("System.Int32"));
        dt.Columns.Add(dc2);

        DataRow dr1 = dt.NewRow();
        dr1["catalog_id"] = 41;
        dt.Rows.Add(dr1);

        DataRow dr2 = dt.NewRow();
        dr2["catalog_id"] = 21;
        dt.Rows.Add(dr2);

        DataRow dr3 = dt.NewRow();
        dr3["catalog_id"] = 55;
        dt.Rows.Add(dr3);

        DataRow dr4 = dt.NewRow();
        dr4["catalog_id"] = 33;
        dt.Rows.Add(dr4);

        GridView1.DataSource = dt;
        GridView1.DataBind();

        string id = "";

        for (int i = 0, max = dt.Rows.Count; i < max; i++)
        {
            id += dt.Rows[i]["catalog_id"].ToString() + ",";
        }
        id = id.Substring(0, id.Length - 1);
        Response.Write(id);

------解决方案--------------------
string PurviewIdstr = ",";
for (int j = 0; j < cb_purview.Items.Count; j++)
{
if (cb_purview.SelectedValue == "")
{
HongShangProject.Common.MessageBox.Show(this, "未选择任何权限,请选择!");
}
else
{
if (cb_purview.Items[j].Selected)
{
int _pid = 0;
int.TryParse(cb_purview.Items[j].Value.Trim(), out _pid);
PurviewIdstr += _cid + "-" + _pid + ",";
}
}
}
------解决方案--------------------
缺少
C# code
using System.Data;