Παίδες, καλύτερα είναι αυτή η υλοποίηση:
Using sqlCn As SqlConnection = New SqlClient.SqlConnection
sqlCn.ConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True"
Try
sqlCn.Open()
Dim strSQL As String
strSQL = "UPDATE Test2 SET Name=@Name,ListPrice=@ListPrice, ProductID=@ProductIDNew" & _
" WHERE ProductID=@ProductIDOld"
strSQL = "SELECT Name,ListPrice, ProductID FROM Test2 WHERE ListPrice > " & TextBox1.Text
Using sqlCmd As SqlCommand = New SqlCommand(strSQL, sqlCn)
Using sqlReader As SqlDataReader = sqlCmd.ExecuteReader
MsgBox(sqlCmd.CommandText)
Dim ordProductID As Integer = sqlReader.GetOrdinal("ProductID")
Dim ordName As Integer = sqlReader.GetOrdinal("Name")
Do While sqlReader.Read
Dim strData As String = sqlReader.GetValue(ordProductID).ToString & _
" - " & sqlReader.GetString(ordName)
ListBox1.Items.Add(strData)
Loop
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
Το Using δεν χρειάζεται Dispose, κλπ, that's the beauty!
Vir prudens non contra ventum mingit