50分不够可以在加呀! 关于取出最大值加一的问题!!急呀!!!

zhllhzzhl 2005-09-19 01:18:18
哪位大哥请帮帮忙呀?
下面的程序单击Command5时可以插入text1.Text的值给字段CRdId没有问题的。
Private Sub Command5_Click()

Dim strQuery As String
Dim rsc As ADODB.Recordset
strUId = "sa"
strPwd = "sa"
strServer = "AH"
strDataBase = "WareHouse001"
strQuery = "select CRdId,CRdName,IRdGrade,BRdFlag from As_Style"
Set rsc = New ADODB.Recordset
rsc.Open strQuery, conn, adOpenStatic, adLockOptimistic

rsc.AddNew
rsc.Fields("CRdId") = text1.Text
rsc.Update
rsc.Close

End If
End Sub

我想先实现:

单击另外一个按钮Command4时,调出数据库中CRdId的最大值并自动加1,显示在text1.Text上面,该如何做呢?急呀!
...全文
262 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugchen888 2005-09-19
  • 打赏
  • 举报
回复
select isnull(max(CRdId),-1)+1 as 'max' from As_Style
wgsasd311 2005-09-19
  • 打赏
  • 举报
回复
Private Sub Command4_Click()

Dim strQuery As String
Dim rsc As ADODB.Recordset
strUId = "sa"
strPwd = "sa"
strServer = "AH"
strDataBase = "WareHouse001"
strQuery = "select cast(max(CRdId)+1 as varchar(9)) as 'max' from As_Style"
Set rsc = New ADODB.Recordset
rsc.Open strQuery, conn, adOpenStatic, adLockOptimistic

rsc.movefirst
text1.text=rsc(1)

End Sub
wgsasd311 2005-09-19
  • 打赏
  • 举报
回复
Private Sub Command4_Click()

Dim strQuery As String
Dim rsc As ADODB.Recordset
strUId = "sa"
strPwd = "sa"
strServer = "AH"
strDataBase = "WareHouse001"
strQuery = "select max(CRdId) as 'max' from As_Style"
Set rsc = New ADODB.Recordset
rsc.Open strQuery, conn, adOpenStatic, adLockOptimistic

rsc.movefirst
text1.text=rsc(1)

End Sub
quhaihua 2005-09-19
  • 打赏
  • 举报
回复
select (max(CRdId)+1) as CRdId,CRdName,IRdGrade,BRdFlag from As_Style

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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