vbnet Parametrised SQL

Private Sub LookupURL()
	Dim conn As New SqlConnection(My.Settings.slickurls)
	Dim cmd As SqlCommand = New SqlCommand()
	Dim dr As SqlDataReader

	With cmd
		.CommandText = "Select Top 1 [Url] From Urls Where UrlKey = @UrlKey Order By DateAdded Desc" 'selects latest Url as duplicates may be present
		.CommandType = CommandType.Text
		.Parameters.AddWithValue("@UrlKey", UrlKey)
		.Connection = conn
		.Connection.Open()
		dr = .ExecuteReader()
	End With

	While dr.Read
		Url = dr("Url").ToString
	End While

	dr.Close()

	With cmd
		.Connection.Close()
		.Connection.Dispose()
		.Dispose()
	End With
End Sub
Parametrised SQL - as used on slck.it

Updated: Saturday 9th October 2010, 17:53pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.