Fordraiders
asked on
how to get sql server express to accept a textbox value to a stored procedure
sql server 2008 sp2
excel 2010: Userform with textbox
I need to see if there are examples or other help places where i can see how to pass a variable to a stored procedure in sql server 2008.
I have a dsn connection a sql server.
Thanks
fordraiders
excel 2010: Userform with textbox
I need to see if there are examples or other help places where i can see how to pass a variable to a stored procedure in sql server 2008.
I have a dsn connection a sql server.
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I slighly changed the textbox1 but will still not return data.
Dim objMyConn As New ADODB.Connection
Dim objMyRecordset As New ADODB.Recordset
Set objMyConn = New ADODB.Connection
objMyConn.CursorLocation = adOpenStatic
Dim strSQL As String
objMyConn.Open "Provider=SQLOLEDB;Data Source=R9NY9X4;Initial Catalog=XRef_Master_TD;Tru sted_conne ction=yes; "
strSQL = "exec get_View_SAP_Listbox1 '" + UserForm2.TextBox1.Text + "'"
With objMyRecordset
.ActiveConnection = objMyConn
.Open strSQL
If Not .EOF Then
MsgBox "Yep" 'has a result
Else
MsgBox "nope" 'doesn't have a result
End If
.Close
End With
in stored procedure: in sql sexpress
ALTER PROCEDURE [dbo].[get_View_SAP_Listbo x1](
@param1 nvarchar(30) --Input
)
AS
BEGIN
SELECT * from xreftable where mfrnumber = @param1
Dim objMyConn As New ADODB.Connection
Dim objMyRecordset As New ADODB.Recordset
Set objMyConn = New ADODB.Connection
objMyConn.CursorLocation = adOpenStatic
Dim strSQL As String
objMyConn.Open "Provider=SQLOLEDB;Data Source=R9NY9X4;Initial Catalog=XRef_Master_TD;Tru
strSQL = "exec get_View_SAP_Listbox1 '" + UserForm2.TextBox1.Text + "'"
With objMyRecordset
.ActiveConnection = objMyConn
.Open strSQL
If Not .EOF Then
MsgBox "Yep" 'has a result
Else
MsgBox "nope" 'doesn't have a result
End If
.Close
End With
in stored procedure: in sql sexpress
ALTER PROCEDURE [dbo].[get_View_SAP_Listbo
@param1 nvarchar(30) --Input
)
AS
BEGIN
SELECT * from xreftable where mfrnumber = @param1
does strSql look correct?
if you open a connection to Xref_Master_Td with your own account and paste in strSql do you get back results?
if you open a connection to Xref_Master_Td with your own account and paste in strSql do you get back results?
ASKER
thanks
' Format: Execute_Select_with_Para(N
Function Execute_Select_with_Param(
Dim ureg As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim param As New ADODB.Parameter
ureg.Open(UREGCONN)
cmd.let_ActiveConnection(u
cmd.CommandType = ADODB.CommandTypeEnum.adCm
cmd.CommandText = "dbo." & ProcName
param = cmd.CreateParameter(PName,
cmd.CommandTimeout = 600
cmd.Parameters.Append(para
Return cmd.Execute
End Function
Sub MyRoutine
Dim records as New ADODB.Recordset
records = Execute_Select_with_Param(
End sub