views:

79

answers:

2

I'm not having any errors from these pieces of code, they're just empty everytime. I'm wondering if I perhaps have created them incorrectly. Help as always, hugely appreciated;

Dim l As New Log()
l.Log = "Attempted staff login with username [" & txtUsername.Text & "]"
l.LogId = 0
l.StaffId = 4
l.LogDate = Date.Now()
l.Insert()

.Insert() is picked up in my BLL layer by these two functions;

Public Function Insert() As Integer
            Return InsertLog(Me.LogId, Me.Log, Me.StaffId, Me.LogDate)
        End Function

        Public Shared Function InsertLog(ByVal logid As Integer, ByVal log As String, ByVal staffid As Integer, ByVal logdate As DateTime) As Integer
            Using scope As New TransactionScope()
                Dim record As New LogDetails(logid, log, staffid, logdate)
                Dim ret As Integer = SiteProvider.Avalon.InsertLog(record)
                scope.Complete()
                Return ret
            End Using
        End Function

In the DAL InsertLog is;

 Public Overrides Function InsertLog(ByVal log As LogDetails) As Integer
            Using cn As New SqlConnection(Me.ConnectionString)
                Dim cmd As New SqlCommand("sp_log_Insert", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@log", log.Log)
                cmd.Parameters.AddWithValue("@staff_id", log.StaffId)
                cmd.Parameters.AddWithValue("@log_date", log.LogDate)

                Dim param As New SqlParameter
                param.Direction = ParameterDirection.ReturnValue
                cmd.Parameters.Add(param)

                cn.Open()
                Dim ret As Integer = ExecuteNonQuery(cmd)
                Return CInt(Convert.ToInt32(param.Value))
            End Using
        End Function

I get the correct return (the db row id) from the final function - but the correct data isn't being inserted, I'm getting the default data I set up for the Property's within LogDetails. Can anyone see what I might be doing wrong here?

Help hugely appreciated :)

As requested: DAL : LogDetails

Imports Microsoft.VisualBasic
Namespace Harmony.Zizz.DAL
    Public Class LogDetails
        Protected _logid As Integer = 0
        Protected _log As String = ""
        Protected _staffid As Integer = 0
        Protected _logdate As DateTime = Date.Now

        Public Sub New()

        End Sub

        Public Sub New(ByVal logid As Integer, ByVal log As String, ByVal staffid As Integer, ByVal logdate As DateTime)

        End Sub

        Public Property LogId() As Integer
            Get
                Return _logid
            End Get
            Set(ByVal value As Integer)
                _logid = value
            End Set
        End Property
        Public Property Log() As String
            Get
                Return _log
            End Get
            Set(ByVal value As String)
                _log = value
            End Set
        End Property
        Public Property StaffId() As Integer
            Get
                Return _staffid
            End Get
            Set(ByVal value As Integer)
                _staffid = value
            End Set
        End Property
        Public Property LogDate() As DateTime
            Get
                Return _logdate
            End Get
            Set(ByVal value As DateTime)
                _logdate = value
            End Set
        End Property
    End Class
End Namespace
+2  A: 

You need to set the private fields to the values send to your second contructor of LogDetails:

Public Sub New(ByVal logid As Integer, ByVal log As String, ByVal staffid As Integer, ByVal logdate As DateTime)
    _logid = logid
    _log = log
    _staffid = staffid
    _logdate = logdate
End Sub
Yogesh
you beat me by 41 secs!
TheVillageIdiot
I knew should just offered that even before asking that the constructor be shown.
AnthonyWJones
+1  A: 

what the hell is this?

Public Sub New(ByVal logid As Integer, ByVal log As String, 
            ByVal staffid As Integer, ByVal logdate As DateTime)

End Sub

change it to this:

Public Sub New(ByVal logid As Integer, ByVal log As String, 
                   ByVal staffid As Integer, ByVal logdate As DateTime)

    _logid = logid
    _staffid = staffid
    _logdate = logdate

End Sub
TheVillageIdiot
*facepalm* Good Lord! Thanks guys, sometimes I just can't see the wood for the trees. Sorry it was something so inane in the end! +1 to both.
Chris Laythorpe