Public Function NextID(ByVal strTable As String, ByVal strID As String) As Long '两个参数分别是表的名称与主键的名称 dim g_Cn as adodb.connection Dim rs As adodb.Recordset g_Cn.open "数据库连接" Set rs = g_Cn.Execute("SELECT MAX(" & strID & ") FROM " & strTable) If IsNull(rs(0)) Then '如果值为NULL,则说明无任何数据记录,此时ID应为1 NextID = 1 Else '使新ID为最大ID值+1 NextID = rs(0).Value + 1 End If End Function 通过以上代码就可以自动添加ID的值2.数据库已经设置为自动增长了,所以根本就不用去管它,在编程中,可以直接跳过这个问题 ,就当这个字段不存在就可以了~建议楼主拿出点代码来,看看~具体问题具体分析~
Public Function NextID(ByVal strTable As String, ByVal strID As String) As Long '两个参数分别是表的名称与主键的名称
dim g_Cn as adodb.connection Dim rs As adodb.Recordset g_Cn.open "数据库连接" Set rs = g_Cn.Execute("SELECT MAX(" & strID & ") FROM " & strTable) If IsNull(rs(0)) Then '如果值为NULL,则说明无任何数据记录,此时ID应为1 NextID = 1 Else '使新ID为最大ID值+1 NextID = rs(0).Value + 1 End If End Function 通过以上代码就可以自动添加ID的值2.数据库已经设置为自动增长了,所以根本就不用去管它,在编程中,可以直接跳过这个问题
,就当这个字段不存在就可以了~建议楼主拿出点代码来,看看~具体问题具体分析~