I have a web app that takes user entered data (in this case a MAC address) calls a stored procedure with output parameters. and is suppoesed to return the switch address and the Slot/Port info from a SQL database. Its not working... Maybe there would be an easier way to do this!?This is what I've got....the Function that calls the stored procedurePublic Function GetSwitchInfo(ByVal MyProc As String, ByVal MMAC As String) As Integer strConn = SQL_CONNECTION_STRING Dim scnClientUpdate As New SqlConnection(strConn) Dim scmd As New SqlCommand(MyProc, scnClientUpdate) Dim sda As New SqlDataAdapter(scmd) Dim dsSWitchInfo As New DataSet scmd.CommandType = CommandType.StoredProcedure With scmd.Parameters .Add(New SqlParameter("@MMAC", SqlDbType.VarChar, 17)).Value = MMAC .Add(New SqlParameter("@Switch", SqlDbType.VarChar, 17)).Direction = ParameterDirection.Output .Add(New SqlParameter("@Port", SqlDbType.VarChar, 17)).Direction = ParameterDirection.Output End With Try sda.Fill(dsSwitchInfo) DataGrid1.DataSource = dsSwitchInfo.Tables(MyProc).DefaultView DataGrid1.DataBind() Catch exp As Exception strErrorMsg = "Error! SwitchInfo NOT " & _ "updated. Error message: " & exp.Message Exit Function End Try MySwitchInfo = scmd.Parameters("@Switch").Value() MyPortInfo = scmd.Parameters("@Port").Value() sda.Dispose() scnClientUpdate.Close() End Function
The stored procedureCREATE PROCEDURE spSwitch @MMAC varchar(17), @Switch varchar(17) OUTPUT, @Port varchar(17) OUTPUT AS Select @Switch = Device FROM UserTrackerInfo WHERE (MACAddress = @MMAC) Select @Port = Port FROM UserTrackerInfo WHERE (MACAddress = @MMAC)GO
I also tried what I thought would be the simple way.. But even thought it does work, I can't seem to figure out how to bind the results to an ASP textbox.'Dim mySwitch As SqlCommand = New SqlCommand("SELECT Device as [Switch Address], Port as [Slot/Port] FROM dbo.UserTrackerInfo WHERE (MACAddress = '" & MMAC & "')", myConn) myConn.Open() Dim SwitchReader As SqlDataReader = mySwitch.ExecuteReader() DataGrid1.DataSource = SwitchReader DataGrid1.DataBind() myConn.Close() SwitchReader.Close()
Any help would be appreciated