//新增加的部分,返回结构数组用于绑定控件 函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle /**//// <summary> /// 运行SQl语句返回结构数组BaseTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> public BaseTitle[] RunSqlStructBaseTitle(string SQL,string SQLForCount,int TitleCount,string DateFormat,int IntroCount) ...{ string strRowCount = RunSqlGetID(SQLForCount); if (strRowCount == null) return null; int DataCount = Int32.Parse(strRowCount); if (DataCount <1) return null; return RunSqlStructBT(SQL,DataCount,TitleCount,DateFormat,IntroCount); } #endregion 函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle /**//// <summary> /// 运行SQl语句返回结构数组BaseTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> public BaseTitle[] RunSqlStructBaseTitle(string SQL,int DataCount,int TitleCount,string DateFormat,int IntroCount) ...{ if (DataCount <1) return null; return RunSqlStructBT(SQL,DataCount,TitleCount,DateFormat,IntroCount); } #endregion 函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle /**//// <summary> /// 运行SQl语句返回结构数组BaseTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> private BaseTitle[] RunSqlStructBT(string SQL,int DataCount,int TitleCount,string DateFormat,int IntroCount) ...{ //返回ID 传入查询语句,返回第一条记录的第一的字段的值 SetCommand(SQL,1); //设置command try ...{ if (cm.Connection.State == ConnectionState.Broken || cm.Connection.State == ConnectionState.Closed ) cm.Connection.Open(); BaseTitle[] strValue = new BaseTitle[DataCount]; SqlDataReader r = cm.ExecuteReader(); int i = 0; while (r.Read()) ...{ //主键 strValue[i].ID = r[0].ToString(); //网址 strValue[i].URL = r[1].ToString(); //判断截取字符数 if (TitleCount == 0) ...{ strValue[i].AllTitle = r[2].ToString(); strValue[i].Title = r[2].ToString(); } else ...{ strValue[i].AllTitle = r[2].ToString(); strValue[i].Title = JYK.Functions.strCal(r[2].ToString(),TitleCount); } //判断时间 if (DateFormat.Length == 0 ) strValue[i].AddedDate = ""; else strValue[i].AddedDate = DateTime.Parse(r[3].ToString()).ToString(DateFormat); //人气 strValue[i].Hits = r[4].ToString(); //图片路径 strValue[i].ImagePath = r[5].ToString(); //内容简介 if (IntroCount == 0) strValue[i].Introduction = r[6].ToString(); else strValue[i].Introduction = JYK.Functions.strCal(r[6].ToString(),IntroCount); i++; }// if (i == 0)// {// //没有数据,返回空// return null;// }// else if (i < DataCount )// {// //记录数不够用,修改数组大小// BaseTitle[] tmp = new BaseTitle[i];// int j = 0;// foreach(BaseTitle tt in strValue)// {// tmp[j].Hits = tt.Hits ;// tmp[j].ID = tt.ID ;// tmp[j].ImagePath = tt.ImagePath ;// tmp[j].Introduction = tt.Introduction ;// tmp[j].Title = tt.Title ;// tmp[j].URL = tt.URL ;// j++;// if (j == i )// break;// }// return tmp;// }// else// {// return strValue;// } return strValue; } catch(Exception ex) ...{ SetErrorMsg("RunSqlStructBT",SQL,ex.Message ); //处理错误 return null; } finally ...{ if (!isUseTrans) cm.Connection.Close(); } } #endregion //===================================================================== 函数实现 — — RunSqlStructCusTitle#region 函数实现 — — RunSqlStructCusTitle /**//// <summary> /// 运行SQl语句返回结构数组 CusTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> public CusTitle[] RunSqlStructCusTitle(string SQL,string SQLForCount) ...{ string strRowCount = RunSqlGetID(SQLForCount); if (strRowCount == null) return null; int DataCount = Int32.Parse(strRowCount); if (DataCount <1) return null; return RunSqlStructCT(SQL,DataCount); } #endregion 函数实现 — — RunSqlStructCusTitle#region 函数实现 — — RunSqlStructCusTitle /**//// <summary> /// 运行SQl语句返回结构数组 CusTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> public CusTitle[] RunSqlStructCusTitle(string SQL,int DataCount) ...{ if (DataCount <1) return null; return RunSqlStructCT(SQL,DataCount); } #endregion 函数实现 — — RunSqlStructCT#region 函数实现 — — RunSqlStructCT /**//// <summary> /// 运行SQl语句返回结构数组 CusTitle /// </summary> /// <param name="SQL">查询语句。比如select myName from tableName</param> /// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param> /// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param> /// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param> /// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns> private CusTitle[] RunSqlStructCT(string SQL,int DataCount) ...{ //返回ID 传入查询语句,返回第一条记录的第一的字段的值 SetCommand(SQL,1); //设置command try ...{ if (cm.Connection.State == ConnectionState.Broken || cm.Connection.State == ConnectionState.Closed ) cm.Connection.Open(); CusTitle[] strValue = new CusTitle[DataCount]; SqlDataReader r = cm.ExecuteReader(); int i = 0; int ArrLength = r.FieldCount-2; while (r.Read()) ...{ //ID strValue[i].ID = r[0].ToString(); //标题 strValue[i].Title = r[1].ToString(); //其他 strValue[i].str = new string[ArrLength]; for(int j=0;j<ArrLength;j++) strValue[i].str[j] = r.GetValue(j+2).ToString(); i++; } return strValue; } catch(Exception ex) ...{ SetErrorMsg("RunSqlStrs",SQL,ex.Message ); //处理错误 return null; } finally ...{ if (!isUseTrans) cm.Connection.Close(); } } #endregion //===========================end============================== 由于代码比较长,所以呢分成几个部分显示。