vbnet Insert Record into DB

Private Function InsertUrl() As Boolean
	Dim s As New StringBuilder
	Dim ServerVariables As String = ""
	Dim IP As String = Request.ServerVariables("REMOTE_ADDR").ToString()
	Dim RowsAffected As Int32 = 0
	Dim conn As New SqlConnection(My.Settings.slickurls)
	Dim cmd As SqlCommand = New SqlCommand()

	For Each x In Request.ServerVariables
		s.Append(x & ":" & Request.ServerVariables(x).ToString & "|")
	Next

	ServerVariables = s.ToString

	With cmd
		.CommandText = "InsertUrl"
		.CommandType = CommandType.StoredProcedure
		.Parameters.AddWithValue("@UrlKey", UrlKey)
		.Parameters.AddWithValue("@Url", UrlIn)
		.Parameters.AddWithValue("@Title", UrlTitle)
		.Parameters.AddWithValue("@IP", IP)
		.Parameters.AddWithValue("@ServerVariables", ServerVariables)

		.Connection = conn
		.Connection.Open()
		RowsAffected = .ExecuteNonQuery()
		.Connection.Close()
		.Connection.Dispose()
		.Dispose()
	End With

	If RowsAffected > 0 Then
		Return True
	Else
		Return False
	End If
End Function
Inserts a record into a database - as used on slck.it

Updated: Saturday 9th October 2010, 11:56pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.