Public Function Create_OCPBlacklist(ByVal cn As SqlConnection, ByVal rec As OCPBlacklist, Optional ByVal myTrans As SqlTransaction = Nothing) As Int32
SyncLock cn
Dim SQL As String
Dim cmd As SqlCommand
rec.Pseudokey = 0
SQL = "INSERT INTO OCPBlacklist (" & _
" BlacklistSubnet, Author, Comments, Disabled, Created," & _
" LastUsed, UseCount " & _
") OUTPUT INSERTED.Pseudokey VALUES (" & _
"@BlacklistSubnet,@Author,@Comments,@Disabled,@Created," & _
"@LastUsed,@UseCount " & _
")"
cmd = New SqlCommand(SQL, cn)
cmd.Parameters.Add("@Pseudokey",SqlDbType.int).Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add("@BlacklistSubnet",SqlDbType.varchar,255).Direction = ParameterDirection.Input
cmd.Parameters.Add("@Author",SqlDbType.varchar,100).Direction = ParameterDirection.Input
cmd.Parameters.Add("@Comments",SqlDbType.varchar,255).Direction = ParameterDirection.Input
cmd.Parameters.Add("@Disabled",SqlDbType.bit).Direction = ParameterDirection.Input
cmd.Parameters.Add("@Created",SqlDbType.datetime).Direction = ParameterDirection.Input
cmd.Parameters.Add("@LastUsed",SqlDbType.datetime).Direction = ParameterDirection.Input
cmd.Parameters.Add("@UseCount",SqlDbType.int).Direction = ParameterDirection.Input
cmd.Parameters("@BlacklistSubnet").Value = rec.BlacklistSubnet
If rec.Author = String.Empty Then
cmd.Parameters("@Author").Value = DBNull.Value
Else
cmd.Parameters("@Author").Value = rec.Author
End If
If rec.Comments = String.Empty Then
cmd.Parameters("@Comments").Value = DBNull.Value
Else
cmd.Parameters("@Comments").Value = rec.Comments
End If
cmd.Parameters("@Disabled").Value = rec.Disabled
If rec.Created = DateTime.MinValue Then
cmd.Parameters("@Created").Value = DBNull.Value
Else
cmd.Parameters("@Created").Value = rec.Created
End If
If rec.LastUsed = DateTime.MinValue Then
cmd.Parameters("@LastUsed").Value = DBNull.Value
Else
cmd.Parameters("@LastUsed").Value = rec.LastUsed
End If
If rec.UseCount = 0 Then
cmd.Parameters("@UseCount").Value = DBNull.Value
Else
cmd.Parameters("@UseCount").Value = rec.UseCount
End If
If Not myTrans Is Nothing Then
cmd.Transaction = myTrans
End If
Dim retVal As Object = cmd.ExecuteScalar()
rec.Pseudokey = CType(retVal,Int32)
cmd.Dispose()
cmd = Nothing
End SyncLock
Return rec.Pseudokey
End Function