2009-11-12 68 views
0

我沒有從這些代碼中發現任何錯誤,他們只是每次都是空的。我想知道我是否可能錯誤地創建了它們。一如既往的幫助,非常感謝;傳遞給Function的對象,但未收到...爲什麼?

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()在我的BLL層被這兩個函數拾取;

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 

在DAL中插入日誌是;

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 

我從最終函數正確的返回(分貝行ID) - 但正確的數據沒有被插入,我得到我設立了物業的LogDetails內默認的數據。任何人都可以看到我可能在這裏做錯了嗎?

幫助非常感激:)

按照要求: 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 
+0

顯示使用的代碼ESP的LogDetails。它的構造函數 – AnthonyWJones 2009-11-12 09:37:50

+0

嗨安東尼,我已經添加了LogDetails類。這是從DAL中導入到BLL的頂部,在那裏調用.Inserts()。我也有一個Log類,在我的BLL中看起來完全一樣,這是基於我對n層體系結構的理解,但很可能是錯誤的...... – dooburt 2009-11-12 09:45:17

回答

2

您需要設置私有字段的值發送到您的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 
+0

你在41秒內擊敗了我! – TheVillageIdiot 2009-11-12 10:03:14

+0

我知道應該提出,即使在詢問構造函數被顯示之前。 – AnthonyWJones 2009-11-12 16:33:58

1

這是什麼?

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

End Sub 

它改成這樣:

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 
+0

* facepalm *好主!謝謝你們,有時我只是看不到樹木。對不起,它最終是如此愚蠢! +1兩者。 – dooburt 2009-11-12 10:12:49

相關問題