【吊儿郎当】流水号截取字段后怎么取最大?

mzjmicrosoft 2010-01-13 11:04:53
注:Access数据库(对这不太熟悉...)

句子:select MID(F_Code,4,14) from DepotM 我想取最大一条记录然后在截取?

初次尝试 select MAX(MID(F_Code,4,14)) from DepotM ,报错:确保列表中的最大索引小于列表的大小

正确:select top 1 * from (select F_ID,MID(F_Code,4,14) as tmp from DepotM) order by tmp desc
正确结果:
F_ID temp
1 20100101130001
----------------------------------------
PS:原表结构
F_ID F_Code
0 CGD20091210110001
1 CGD20100101130001
----------------------------------------
现在问题来了:

OleDbDataReader oleReader = oleCmd.ExecuteReader();
while (oleReader.Read())
{
//GoodsCode = oleReader["temp"].ToString();//这个值怎么取
}

每次取都报:确保列表中的最大索引小于列表的大小.....

请高手指教!!100分
...全文
119 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aellonxie 2010-01-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lidanzi 的回复:]
正确:select top 1 * from (select F_ID,MID(F_Code,4,14) astmp from DepotM) order by tmp desc

//GoodsCode = oleReader["temp"].ToString();//这个值怎么取

[/Quote]

取值跟命名不一致
mzjmicrosoft 2010-01-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lidanzi 的回复:]
正确:select top 1 * from (select F_ID,MID(F_Code,4,14) astmp from DepotM) order by tmp desc

//GoodsCode = oleReader["temp"].ToString();//这个值怎么取

[/Quote]

撞墙.................
mzjmicrosoft 2010-01-13
  • 打赏
  • 举报
回复
fw 3.5:

2.0呢..........
wiki14 2010-01-13
  • 打赏
  • 举报
回复
数组越界,索引值超出了最大范围了~
手抓宝 2010-01-13
  • 打赏
  • 举报
回复
OleDbDataReader oleReader = oleCmd.ExecuteReader();
fw 3.5:
IList<string> listString=new List<string>();
while (oleReader.Read())
{
listString.add(oleReader["temp"].ToString());
}
IList<int> listInt=(from i in listString select Convert.ToInt32(i.substring(3,i.length))).toList<int>();

int iResult=listInt.Max();

手敲的,自己调下吧.
lidanzi 2010-01-13
  • 打赏
  • 举报
回复
正确:select top 1 * from (select F_ID,MID(F_Code,4,14) as tmp from DepotM) order by tmp desc

//GoodsCode = oleReader["temp"].ToString();//这个值怎么取

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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