下面是一个用于显示用户输入的字符串的方法,只要用户输入什么,就会显示所输入的字符,但是有些地方我分析不了,(水平有限,本来目的就是分析它,以增加自己的水平),
我觉得难点就在:那个循环里,不好分析。
请各位指教指教:
public void ListClass() //显示分类
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_selFclassAll",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();
int i=2;
while (rd.Read())
{
if(i>40)
{
Literal1.Text+="<br>";//如何理解
i=0;
}//为什么要这样循环?
Literal1.Text+="<a href=./list.aspx?classname="+rd.GetString(1)+">"+rd.GetString(1).Trim()+"</a>"+"||";
i += rd.GetString(1).Trim().Length;
}
rd.Close();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
我觉得难点就在:那个循环里,不好分析。
请各位指教指教:
public void ListClass() //显示分类
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_selFclassAll",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();
int i=2;
while (rd.Read())
{
if(i>40)
{
Literal1.Text+="<br>";//如何理解
i=0;
}//为什么要这样循环?
Literal1.Text+="<a href=./list.aspx?classname="+rd.GetString(1)+">"+rd.GetString(1).Trim()+"</a>"+"||";
i += rd.GetString(1).Trim().Length;
}
rd.Close();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
解决方案 »
- Microsoft.Office.Interop.Excel.Worksheet 转 Microsoft.Office.Tools.Excel.Workshee
- SMGP(短信平台) c# Report id 乱码问题
- 想在服务器上添加一种服务,给点提示
- 非托管内存的释放。。
- VS2005开发的winForm程序,制作安装包,安装时自动调用另一执行文件的问题?
- 关于C# 中 string 转换 int 提示:确保不会被0整除?
- 捕获datagrid的事件。
- DataGrid排序,修改问题 立即给分
- C#加入FLASH按纽
- 请问C#和vc++有什么区别?
- 江湖救急,高手请进,有关页间传值的问题!!!
- 是否能用程序通过修改树属性来改变树内容
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn = new SqlConnection(con);//连接字符串
conn.Open();
SqlCommand cmd=new SqlCommand("sp_selFclassAll",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();
int i=2;
while (rd.Read())
{
if(i>40)
{
Literal1.Text+="<br>";//如果字符串的宽度大于40就添加一个换行符号<br>
i=0; //如果字符串宽度大于40就重设为0,重新累计
}//为什么要这样循环?
//这样循环的主要目的就是要实现换行,!!!
Literal1.Text+="<a href=./list.aspx?classname="+rd.GetString(1)+">"+rd.GetString(1).Trim()+"</a>"+"||";
i += rd.GetString(1).Trim().Length;//累计字符串的宽度
}
rd.Close();
conn.Close();
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出错处理
}
}
这一句是否根据循环每次读取,直到读完?又是根据那个参数来判断读完?
或者它一次性读完rd?从首到尾?Trim(),这个我不太熟悉。
表示40个字符的时候就换行,保证页面的美观i += rd.GetString(1).Trim().Length 表示单行字符窜类加,算出它的长度
各位帮我解释这句的用法,我不知如何来理解