我的Web應用程序由單擊時從數據庫檢索信息的URL列表組成。應用程序的工作以及使用以下非存儲過程方法:單擊URL時,存儲過程不呈現數據
代碼:
Retrieve the connection string stored in the Web.config file.
Dim connectionString As [String] = ConfigurationManager.ConnectionStrings("dbName_dbConnectionString").ConnectionString
Dim connection As New SqlConnection(connectionString)
connection.Open()
Dim mySQLQuery As String
Dim vID As String
vID = Request.QueryString("submittalList")
mySQLQuery = "SELECT submittalsInfo.CategoryID, submittalsInfo.url, submittalsInfo.headerName, submittalsInfo.FileName FROM submittals INNER JOIN submittalsInfo ON submittals.CategoryID = submittalsInfo.CategoryID WHERE (submittalsInfo.CategoryID = submittals.CategoryID) AND submittalsInfo.CategoryID = '" & vID & "' AND submittalsInfo.isActive = '1' ORDER BY submittalsInfo.FileName"
Dim myCommand As New SqlCommand(mySQLQuery, connection)
Dim myReader1 As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
While (myReader1.Read())
showSubHeader.Text = myReader1.GetString(2).ToString + ":"
showurls.Text = showurls.Text + "<div>" + myReader1.GetString(1).ToString + "</div>"
End While
connection.Close()
...我試圖使用產生的存儲過程相同的結果。以下是我的設置:
存儲過程:
ALTER PROCEDURE [dbo].[showSubmittals]
AS
Begin
SELECT submittalsInfo.CategoryID, submittalsInfo.url, submittalsInfo.headerName, submittalsInfo.FileName FROM submittals INNER JOIN submittalsInfo ON submittals.CategoryID = submittalsInfo.CategoryID WHERE (submittalsInfo.CategoryID = submittals.CategoryID) AND submittalsInfo.CategoryID = '" & vID & "' AND submittalsInfo.isActive = '1' ORDER BY submittalsInfo.FileName
END
...這裏是代碼我使用叫它:
'Retrieve the connection string stored in the Web.config file.
Dim connectionString As [String] = ConfigurationManager.ConnectionStrings("webname_dbConnectionString").ConnectionString
Dim connection As New SqlConnection(connectionString)
Dim myCommand As New SqlCommand()
myCommand.CommandType = CommandType.StoredProcedure
myCommand.CommandText = "showSubmittals"
myCommand.Connection = connection
Try
connection.Open()
Dim myReader1 As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
While (myReader1.Read())
showSubHeader.Text = myReader1.GetString(2).ToString + ":"
showurls.Text = showurls.Text + "<div>" + myReader1.GetString(1).ToString + "</div>"
End While
Catch ex As Exception
Throw ex
Finally
connection.Close()
connection.Dispose()
End Try
...問題我遇到在單擊URL時,頁面(URL)不呈現結果。下面顯示了我的網址是怎麼設置的,我爲了顯示在頁面showSubmittals.aspx,其中包含後端代碼的結果(我的方法)我上面所解釋的:
<asp:HyperLink ID="HyperLink1" runat="server" Text="Accessories" NavigateUrl="~/showSubmittals.aspx?submittalList=1" CssClass="submittalsLinks" />
我能請得到一些關於如何使用存儲過程方法完成此任務的幫助?在此先感謝
存儲過程在SSMS中運行時是否返回數據?來自SQL服務器的存儲過程應該像查詢一樣返回數據。 SQL服務器不像Oracle;它不需要參考光標。 – Doug
您是否嘗試調試並查看執行命令後是否執行while循環? –
爲什麼你的存儲過程有字符串連接的vb語法?您需要在存儲過程中將'vId'作爲參數並從代碼中傳遞。 –