<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %><script runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
 string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
 strConnection+="Data Source=";
 strConnection+=MapPath("data\\data.mdb");
 OleDbConnection objConnection=new OleDbConnection(strConnection);
 OleDbCommand objCommand = new OleDbCommand("select * from 文字 where 位置='index1'" , objConnection);
 objConnection.Open();
 OleDbDataReader objDataReader=objCommand.ExecuteReader();
 if(objDataReader.Read())
 {
  Label1.Text=Convert.ToString(objDataReader["标题"]);
  Label2.Text=Convert.ToString(objDataReader["内容"]);  ******我想控制现实字数不超过10个
 }
 objConnection.Close();
}
</script>
<html>
<head>

解决方案 »

  1.   

    请问如何使用??Label2.Text=Convert.ToString(objDataReader["内容"]);  让这句话的lable2显示10个字符
      

  2.   

    可以在SQL语句里把多余的截除,请参考:
    select id,case when len(title)>22 then(substring(title,0,20)+'...') else title end as title,filltime,pic,name from table
      

  3.   

    你不是想实现Label2.Text的内容不超过10个字符吗?我在Select的时候就把绑定到Label2.Text的这个字段的长度给它截取了。
      

  4.   

    不好意思。我刚接触这个,请问这句应该怎么改截取字符?
    select * from 文字 where 位置='index1'select * wen len(title)>10 then(substring(title,0,10)+'...') else title end as title from '文字' where 位置='index1'
    这样对吗?substring(title,0,10)+'...'什么意思?
    else title end as title 什么意思??
    谢谢大哥
      

  5.   

    select *,wen len(title)>10 then(substring(title,0,10)+'...') else title end as title from '文字' where 位置='index1'不要忘记了*后的','号。substring就是取子字符串的,其语法为:
    SUBSTRING ( expression , start , length )
    expression
    是字符串、二进制字符串、text、image、列或包含列的表达式。不要使用包含聚合函数的表达式。start
    是一个整数,指定子串的开始位置。length
    是一个整数,指定子串的长度(要返回的字符数或字节数)。
      

  6.   

    case when 条件
         符合条件的
    else 
         不符合条件的
    end
      

  7.   

    又出现错误了~5555
    错误代码:
    IErrorInfo.GetDescription failed with E_FAIL(0x80004005). 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
    我的代码:
    for(int i=0;i<=2;i++)
    {int tp=i+1;
     OleDbCommand objCommand = new OleDbCommand("select *,wen len(title)>10 then(substring(title,0,10)+'...') else title end as title from '文字' where 位置='index'"+ tp +"'" , objConnection);
     OleDbDataReader objDataReader=objCommand.ExecuteReader();
     if(objDataReader.Read())
     {   string lcID="lable"+i*3+1;
       Control loCtrl=this.FindControl(lcID);
       if (loCtrl!=null&&loCtrl is Label)
       {
              
         ((Label)loCtrl).Text=Convert.ToString(objDataReader["标题"]);
       }
       
       lcID="lable"+i*3+2;
       loCtrl=this.FindControl(lcID);
       if (loCtrl!=null&&loCtrl is Label)
       {
             ((Label)loCtrl).Text=Convert.ToString(objDataReader["内容"]);
       }
      } }