现在的位置: 首页 > 综合 > 正文

功能函数 遍历datatable

2013年01月10日 ⁄ 综合 ⁄ 共 915字 ⁄ 字号 评论关闭
 public string GetReturnString(DataTable tempDT, int tempColumn)
        {
            string tempStr = "";
            if (!object.Equals(tempDT, null))
            {
                if (tempDT.Rows.Count > 0)
                {
                    for (int i = 0; i < tempDT.Rows.Count; i++)
           {
                        if (tempColumn > tempDT.Columns.Count)
                            tempColumn = tempDT.Columns.Count;
                        for (int c = 0; c <tempColumn ;c++ )
                        {
                            tempStr += Common.StringOperator.GetRightString(tempDT.Rows[i][c]) + ",";
                        }
                        tempStr = tempStr.TrimEnd(',');
                        tempStr += "~$~";
           }
                   
                }
                else
                {
                    tempStr = "null";
                }
            }
            else
            {
                tempStr = "null";
            }
            return tempStr;
        }

抱歉!评论已关闭.