2014-10-31 79 views
0

我正在將負載運行多個程序存儲在頁面上預先填充文本框在頁面內更改存儲過程。VB.net一個SQL連接

,而不用打開,我想使用不同的存儲過程,我想知道是否有可能一個連接中多次改變每次關閉連接。

如這樣的:

Using myConnection1 = New SqlConnection("connectionString") 
myConnection1.Open() 
Dim myCommand As New SqlCommand("storedProdure1", myConnection) 
myCommand.CommandType = CommandType.StoredProcedure 

'additional code here 

End Using 

Using myConnection2 = New SqlConnection("connectionString") 

myConnection2.Open() 
Dim myCommand As New SqlCommand("storeProcedure2", myConnection2) 
myCommand.CommandType = CommandType.StoredProcedure 

'additional code here 

End Using 

可以像這樣的東西來代替:提前

Using myConnection1 = New SqlConnection("connectionString") 
myConnection1.Open() 
Dim myCommand As New SqlCommand("storedProdure1", myConnection) 
myCommand.CommandType = CommandType.StoredProcedure 

'additional code here 

myCommand.alterSqlCommand("storedProcdure2", myConnection) 

'additional code here 

End Using 

感謝

回答

0

當使用正常的SQL命令,你可以這樣寫:

myCommand.CommandText = "..." 

並在打開連接時更改命令。 對於存儲過程也應該如此。只需使用CommandText即可更改StoredProcedure。

希望這會有所幫助。

+0

完美的工作一種享受,謝謝! – 2014-10-31 14:47:36