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上面,该如何做呢?急呀!
...全文
226 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
发帖
应用实例
创建于2007-09-28

2.7w+

社区成员

MS-SQL Server 应用实例
申请成为版主
帖子事件
创建了帖子
2005-09-19 01:18
社区公告
暂无公告