1
當我加載我的頁面時,使用下面的代碼填充我的中繼器。在頁面加載時只連接數據庫一次
Dim conn As Data.SqlClient.SqlConnection
Dim Comm As Data.SqlClient.SqlCommand
Dim reader As Data.SqlClient.SqlDataReader
'conn = New Data.SqlClient.SqlConnection("Server=localhost\sqlexpress; " & _
'"Database=MyDB; Integrated Security=true")
conn = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
Comm = New Data.SqlClient.SqlCommand(_
("HomePage"), conn)
Comm.CommandType = CommandType.StoredProcedure
Comm.Parameters.AddWithValue("@currentState", "Florida")
' Open the connection
conn.Open()
' Execute the category command
reader = Comm.ExecuteReader()
' Bind the reader to the repeater.......
blogRepeater.DataSource = reader
blogRepeater.DataBind()
' Close the reader
reader.Close()
' Close the connection
conn.Close()
End Try
現在我想調用另一個存儲過程(在同一時間),這樣我就可以填充某些文本字段(也頁面加載)。但是,我怎麼能這樣做,以便我只打一次電話給我的數據庫以獲得更好的性能?
C#示例也將工作,如果你不知道VB.NET
在性能vs代碼可維護性競賽中這是最好的選擇 – NotMe 2010-10-12 17:20:37
感謝Man,其實很簡單!謝謝! – Etienne 2010-10-12 17:28:30
@Etienne - 沒問題,很高興我能幫上忙 – 2010-10-12 17:43:38