急求高手帮忙~~~

loveqiudexiaochouyu 2010-05-28 06:16:01
请先看一下这段代码:

private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (comboBox2.DataSource!=null)
{
string sql="select year(enrolmenttime) from classinfo where classid="+comboBox2.SelectedValue;
OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
int rxnf=Int32.Parse(cmd.ExecuteScalar().ToString());
sql="select length from classinfo where classid="+comboBox2.SelectedValue;
cmd.CommandText=sql;
int nianzhi=Int32.Parse(cmd.ExecuteScalar().ToString());
comboBox3.Items.Clear();
int nf=rxnf;
Object item=new object();
for (int i=1;i<=nianzhi*2;i++)
{
comboBox3.Items.Add(nf + "" + ((i + 1) % 2 + 1));

if (i%2==0) nf++;
}
}
else
{
comboBox3.SelectedIndex=-1;
comboBox3.Items.Clear();
}
其中 nf代表年份,nianzhi就是年制。这是学生信息系统中添加课程的一段代码,程序会自动产生班级的每一个学期。利用for循环生成班级学期代码。比如,年制为3年的班级会自动产生6个学期代码。
这段程序运行的结果比如是20062,就代表2006-2007年度第一学期。我想把运行结果换为“2006-2007年度第一学期”,这种表示方式。请高手帮忙看看,急用~~~~~~
...全文
92 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyzsy2008 2010-05-29
  • 打赏
  • 举报
回复
string str=string.format("{0}-{1}年度第{2}学期", nf, nf+ 1, ((i+1)%2+1) )
comboBox3.Items.Add(s);
足球中国 2010-05-29
  • 打赏
  • 举报
回复
楼主写的代码让人看不懂。逻辑有点乱。整理一下楼主应该可以写出来。
  • 打赏
  • 举报
回复
赶快来人帮忙解决一下啊 !
linq-w 2010-05-29
  • 打赏
  • 举报
回复
我只要分数~
醒子宇 2010-05-29
  • 打赏
  • 举报
回复
看看楼主的结贴率

在看看楼主的技术分


人家才懒得帮你```
jianshao810 2010-05-29
  • 打赏
  • 举报
回复
string str=string.format("{0}-{1}年度第{2}学期", nf, nf+ 1, ((i+1)%2+1) )
comboBox3.Items.Add(s);
liuhongwei90 2010-05-29
  • 打赏
  • 举报
回复
string str=string.format("{0}-{1}",跟占位符索引匹配)

{0}占位符 貌似没有限制多少个
  • 打赏
  • 举报
回复
format 怎么定义呢?
  • 打赏
  • 举报
回复
怎么没人给我解答一下啊???
  • 打赏
  • 举报
回复
这样改的话,是不是上面的语句都要改啊?能不能说的具体点?
zpf82118 2010-05-28
  • 打赏
  • 举报
回复
int year = int32.parse(result) / 10;
int index = int32.parse(result) % 10;

string index_str = (index == 1) ? "一" : “二”;
string you_want = string.format("{0}-{1}年度第{2}学期", year, year + 1, index_str);

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧