填写Excel +从Microsoft Sql Management Studio数据库表填充active x comobo框

我有一个Excel文件,我试图从一个Microsoft SQL数据库拉值。 我正在尝试使用与该ID关联的表ID和string值从表中添加值。 我遇到了一个无效的参数错误。 我能够添加xlVal如果我宣布的整数值,并设置第一个项目= 0,然后我可以加1到xlVal使每个整数值唯一,但这些值将不会允许我引用特定的行数据库,如果我想拉回来更新数据库的值。 基本上我想知道是否有一种方法来设置pvargindex值=我的数据库ID值,因为我没有一个整数在我的数据库中以0开始。我也尝试添加一行(select type …,0)之前循环运行,但我无法得到这个工作。

Private Sub populateType() Dim dbName As Object Dim dbResults As Object Set dbName = CreateObject("ADODB.Connection") Set dbName = openDBConn("./System", "System") Set dbResults = dbName.Execute("SELECT ID_Type, Type FROM Const_Type WHERE Active = 1 AND Type <> 'N/A' ORDER BY Type") Sheet1.ComboBox1.Clear Do While Not dbResults.EOF Dim xlStr As String xlStr = dbResults("Type").Value Dim xlVal as integer xlVal = dbResults("ID_Type").Value Sheet1.ComboBox1.AddItem xlStr, xlVal dbResults.MoveNext Loop 

结束小组