2013-03-21 33 views
2

如何在运行期间使用存储过程填充组合框以从数据库获取值?使用vb6中的存储过程填充组合框

这里是我的代码,这应该转换成存储过程:

Private Sub ComboFill() 
Set Rs = New ADODB.Recordset 
Set Cmd = New ADODB.Command 
With Cmd 
.ActiveConnection = Conn 
.CommandType = adCmdText 
.CommandText = "SELECT suppliername from supplier" 
Set Rs = .Execute 
End With 

If Not (Rs.BOF And Rs.EOF) Then 
Rs.MoveFirst 
End If 

Do Until Rs.EOF 
txtsupplier.AddItem Rs.Fields("suppliername").Value 
Rs.MoveNext 
Loop 
End Sub 
+0

你试过了什么? Google仍然是免费的。 – 2013-03-21 16:09:27

+0

@ user2063626:已更新帖子。一探究竟。 – 2013-03-21 16:35:27

回答

2

试试这个(未测试):

编辑:调整返回一个RS,不是一个单一的值

Set Rs = New ADODB.Recordset 
Set cn = New ADODB.Connection 
cn.ConnectionString = Session.GetConnectionstring 
cn.Open 

Set cmd = New ADODB.Command 
cmd.ActiveConnection = cn 
cmd.CommandType = adCmdStoredProc 
cmd.CommandText = “MyStoredProcdure” 
' Input param, if you need 
' cmd.Parameters.Append cmd.CreateParameter(“Param1”, adInteger, adParamInput, , 614) 
' Create a recordset by executing the command. 
Set Rs = cmd.Execute() 
Rs.MoveFirst() 

Do Until Rs.EOF 
    txtsupplier.AddItem Rs.Fields("suppliername").Value 
Rs.MoveNext 

Set Rs = Nothing 
Set cmd = Nothing 
Set cn = Nothing