Which code segment should you insert at line 02?

You use Microsoft .NET Framework 4 to develop an application. You write the following code to
update data in a Microsoft SQL Server 2008 database. (Line numbers are included for reference
only,)
01 Private Sub ExecuteUpdate(ByVal cmd As SqlCommand, ByVal connString As String, ByVal
updateStrat As String)
02
03 End Sub

You need to ensure that the update statement executes and that the application avoids connection
leaks. Which code segment should you insert at line 02?

You use Microsoft .NET Framework 4 to develop an application. You write the following code to
update data in a Microsoft SQL Server 2008 database. (Line numbers are included for reference
only,)
01 Private Sub ExecuteUpdate(ByVal cmd As SqlCommand, ByVal connString As String, ByVal
updateStrat As String)
02
03 End Sub

You need to ensure that the update statement executes and that the application avoids connection
leaks. Which code segment should you insert at line 02?

A.
Dim conn As SqlConnection = New SqlConnection(connString)
conn.Open()
cmd.Connection = conn
cmd.CommondText = updateStmt
cmd. ExecuteNonQuery ()
cmd.Connect ion.Close()

B.
Using conn As New SqlConnection(connString)
cmd.Connection = conn
cmd.CommandText = updateStmt
cmd.ExecuteNonQuery()
cmd.Connection.Close()
End Using

C.
Using conn As New SqlConnection(connString)
conn.Open() cmd.Connection = conn
cmd.CommandText = updateStmt
cmd.ExecuteNonQuery()
End Using

D.
Dim conn As SqlConnection = Nera SqlConnection(connStcing)
conn.Open()
cmd.Connection = conn
cmd.CommandText = updateStmt
cmd.ExecuteNonQuery()

Explanation:
http://www.w3enterprises.com/articles/using.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx



Leave a Reply 0

Your email address will not be published. Required fields are marked *