2013-03-21 73 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