列不属于表Table

时间:2010-09-13 18:30:51

标签: dataset

我不知道我到底要找的确切位置。 错误是:

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

下面是代码片段中调用的dataaccess方法。 现在JudgeDataTable被声明为
Private JudgeDataTable As System.Data.DataTable位于页面顶部。
Rest就在我上面发布的代码片段中。

'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

2 个答案:

答案 0 :(得分: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

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   

答案 1 :(得分:0)

如果你在getdataset之后破解并查看数据表会发生什么?那列是吗?否则,可能尝试通过列索引访问它。