我在网上看见ADODB的代码,但自己在用的时候出错
出错内容:变量类型或者类型不正确,或者不在可以接受的范围之内,要不就是与其他数据冲突
出错行是:rst.Open StrSQL, 3, 2我是在函数下编写的,具体代码如下,SQL语句没问题,我在查询分析器里做过,数据库连接也应该没问题,我是通过ADODC控件生成复制下来的
Public Function NewID(OldDate As Date, IDType As String) As String
Dim DYear As String
Dim DMonth As String
Dim DDay As String
Dim CYear As String
Dim CMonth As String
Dim CDay As String
Dim StrDate As String
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim StrSQL As String
Dim MaxId As String
'生成字符日期
DYear = Year(OldDate)
DMonth = Month(OldDate)
DDay = Day(OldDate)
CYear = Str(DYear)
If DMonth > 9 Then
CMonth = Str(DMonth)
Else
CMonth = "0" + Str(DMonth)
End If
If DDay > 9 Then
CDay = Str(DDay)
Else
CDay = "0" + Str(DDay)
End If
StrDate = CYear + CMonth + CDay
'查找相关记录
cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" _
+ "User ID=sa;Initial Catalog=STORE;Data Source=SHCZSERVER"
cnn.Open
StrSQL = "select max(storeid) as MaxId from gstore where typeid='" + IDType + "' and storeid like '" + StrDate + "%'"
rst.Open StrSQL, 3, 2
NewID = rst.Fields(0)
rst.Close
cnn.Close
Set cnn = Nothing
Set rst = Nothing
End Function
出错内容:变量类型或者类型不正确,或者不在可以接受的范围之内,要不就是与其他数据冲突
出错行是:rst.Open StrSQL, 3, 2我是在函数下编写的,具体代码如下,SQL语句没问题,我在查询分析器里做过,数据库连接也应该没问题,我是通过ADODC控件生成复制下来的
Public Function NewID(OldDate As Date, IDType As String) As String
Dim DYear As String
Dim DMonth As String
Dim DDay As String
Dim CYear As String
Dim CMonth As String
Dim CDay As String
Dim StrDate As String
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim StrSQL As String
Dim MaxId As String
'生成字符日期
DYear = Year(OldDate)
DMonth = Month(OldDate)
DDay = Day(OldDate)
CYear = Str(DYear)
If DMonth > 9 Then
CMonth = Str(DMonth)
Else
CMonth = "0" + Str(DMonth)
End If
If DDay > 9 Then
CDay = Str(DDay)
Else
CDay = "0" + Str(DDay)
End If
StrDate = CYear + CMonth + CDay
'查找相关记录
cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" _
+ "User ID=sa;Initial Catalog=STORE;Data Source=SHCZSERVER"
cnn.Open
StrSQL = "select max(storeid) as MaxId from gstore where typeid='" + IDType + "' and storeid like '" + StrDate + "%'"
rst.Open StrSQL, 3, 2
NewID = rst.Fields(0)
rst.Close
cnn.Close
Set cnn = Nothing
Set rst = Nothing
End Function
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货