2010-09-13 52 views
0

我不知道我在哪裏尋找。 錯誤是:列不屬於表格表

Column 'pkJudge' does not belong to table Table. ' 
    at System.Data.DataRow.GetDataColumn(String columnName) 
    at System.Data.DataRow.set_Item(String columnName, Object value) 
    at ReadyCollect.CaseEntry.S_GetJudges(Int32 courtID) 
    at ReadyCollect.CaseEntry.S_GetExistCaseInfo() 
    at ReadyCollect.CaseEntry.CaseReminder_HoldCase() 
    at ReadyCollect.CaseEntry.btnSave_Click(Object sender, EventArgs e) 

它發生在下面的代碼段。有任何想法嗎?

Private Sub S_GetJudges(ByVal courtID As Integer) 
    ' Load the list of judges ' 
    Dim JudgeSet As New DataSet 
    Dim dv As System.Data.DataView 
    Dim DAl As New DataAccessLayer 
    Dim pfkCourt As Integer = CourtDDL.SelectedValue 

    If ClientKey > 0 And pfkCourt > 0 Then 
     JudgeSet = DAl.GetJudgespkJudgesJudgeNamefkCourt(ClientKey, pfkCourt) 
     JudgeDataTable = JudgeSet.Tables(0) 
     Dim dr As System.Data.DataRow 
     dr = JudgeDataTable.NewRow() 
     dr("pkJudge") = "0" 
     dr("Judge Name") = "(Select a Judge)" 
     JudgeDataTable.Rows.Add(dr) 
     JudgeDDL.SelectedValue = 0 
     JudgeDDL.DataSource = JudgeDataTable.DefaultView 
     dv = JudgeDataTable.DefaultView 
     dv.Sort ="pkJudge ASC" 
     JudgeDDL.DataBind() 
    End If 
End Sub 

而在代碼片段中調用的數據訪問方法如下。 現在JudgeDataTable被宣佈爲
Private JudgeDataTable As System.Data.DataTable在頁面頂部。
其餘部分位於我上面發佈的代碼片段中。

'Retreives fields pkJudge and [Judge Name] from the table Judges where field fkCourt is equal to fkCourt ' 

Public Function GetJudgespkJudgesJudgeNamefkCourt(ByVal ClientKey As Integer, ByVal fkCourt As Integer) As DataSet 
    Dim db As Database = DatabaseFactory.CreateDatabase() 
    Dim sqlCommand As String = "USP_DISPLAYJUDGESPKJUDGEJUDGENAMEFKCOURT" 
    Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 
    db.AddInParameter(dbCommand,"ClientKey", DbType.Int32, ClientKey) 
    db.AddInParameter(dbCommand,"fkCourt", DbType.Int32, fkCourt) 
    Return db.ExecuteDataSet(dbCommand) 
End Function 
+0

你可以通過將代碼放在標籤之間來格式化您的代碼嗎? – Rahul 2010-09-13 18:32:34

回答

0

Partial Class CaseEntry Inherits System.Web.UI.Page

 Private JudgeDataTable As System.Data.DataTable 
     Private Sub S_GetJudges(ByVal courtID As Integer) 

     ' Load the list of judges 
     JudgeDataTable = New System.Data.DataTable 
     Dim JudgeSet As New DataSet 
     Dim dv As System.Data.DataView 
     Dim DAl As New DataAccessLayer 
     Dim pfkCourt As Integer = CourtDDL.SelectedValue 
     If ClientKey > 0 And pfkCourt > 0 Then 
      JudgeSet = DAl.GetJudgespkJudgesJudgeNamefkCourt(ClientKey, pfkCourt) 
      JudgeDataTable = JudgeSet.Tables(0) 
      Dim dr As System.Data.DataRow 
      dr = JudgeDataTable.NewRow() 
      dr("pkJudge") = "0" 
      dr("Judge Name") = "(Select a Judge)" 
      JudgeDataTable.Rows.Add(dr) 
      JudgeDDL.SelectedValue = 0 
      JudgeDDL.DataSource = JudgeDataTable.DefaultView 
      dv = JudgeDataTable.DefaultView 
      dv.Sort = "pkJudge ASC" 
      JudgeDDL.DataBind() 
     End If 
    End Sub 

'Retreives fields pkJudge and [Judge Name] from the table Judges where field fkCourt is equal to fkCourt Public Function GetJudgespkJudgesJudgeNamefkCourt(ByVal ClientKey As Integer, ByVal fkCourt As Integer) As DataSet

Dim db As Database = DatabaseFactory.CreateDatabase() 
    Dim sqlCommand As String = "USP_DISPLAYJUDGESPKJUDGEJUDGENAMEFKCOURT" 
    Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand) 

    db.AddInParameter(dbCommand, "ClientKey", DbType.Int32, ClientKey) 
    db.AddInParameter(dbCommand, "fkCourt", DbType.Int32, fkCourt) 

    Return db.ExecuteDataSet(dbCommand) 
End Function 

0

如果你getdataset東西后突破,並期待在數據表中會發生什麼?那裏是專欄嗎?否則,可能嘗試通過列索引訪問它。

+0

如果該列根本不存在,那麼每次頁面加載時都會出現錯誤。嗯,這只是爲數不多。我可以檢查列的存在。 – sony 2010-09-13 21:10:42

+0

枚舉表中的列集合。這應該告訴你有什麼。 – JoelHess 2010-09-14 02:09:03

+0

我試過通過列索引枚舉,我看到列存在。 – sony 2010-09-14 14:33:33