none
column 'pkJudge' does not belong to table Table RRS feed

  • Question

  • I am new to this typed/untyped dataset concept. I don't know exactly where I have to look for.
    Error is

    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)

     It occurs in the following code fragment. Any Ideas ?

    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


    And the dataaccess method that is called in the code fragment is below.
    Now JudgeDataTable is declared as


    Private JudgeDataTable As System.Data.DataTable on top of the page .
    Rest is in the code fragment as I posted above.

    '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

    Monday, September 13, 2010 5:48 PM

Answers

  • Well, that rules out that idea.

    But again, I come back to the belief that the problem lies with the DatabaseFactory class. Surely someone here is familiar enough with it and/or the Enterprise Library to be able to help!!!

    @Sony, I'm not sure if there's a better Forum to post this question in, but I looked around and saw lots of questions about both DatabaseFactory and Enterprise Library in the ADO.NET Managed Providers Forum: http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/threads/  Maybe you'll  have better luck with this question there.

    Sorry to keep asking you to re-post the question!!


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Friday, September 24, 2010 9:14 PM

All replies

  • Hi,

     

    It looks like the column you are trying to sort the table with does not exist in the datatable. Can you check the following?

     

    * Execute the SP USP_DISPLAYJUDGESPKJUDGEJUDGENAMEFKCOURT and check if PkJudge gets returned as a part of the SP

    * If the SP returns the column, then enumerate the columns in the JudgeDataTable and see if you get pkJudge there.

     

    HTH

    Technocrat_aspire

    Wednesday, September 15, 2010 6:35 AM
  • Hi sonysony,

    You can also check all the column names in JudgeDataTable to see whether column 'pkJudge' exist, something like:

    For Each col As DataColumn In JudgeDataTable.Columns
        Console.WriteLine(col.ColumnName)
    Next

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, September 15, 2010 8:11 AM
    Moderator
  • I had asked sony to re-post this question (he had originally had it stuck to the end of another thread). I felt I couldn't help him in that other thread because I believe the problem lies with the DatabaseFactory class, but I am not familiar with that or with the EnterpriseLibrary.

    It's obvious that pkJudge is not a column in the JudgeDataTable, the question is why? In the previous thread sony said that the Stored Proc returned the data ok, but I don't think it was mentioned in this thread. That said, it might be a good idea to take a look at the DataColumns anyway (put a breakpoint in your code after this line):

    JudgeSet = DAl.GetJudgespkJudgesJudgeNamefkCourt(ClientKey, pfkCourt)

    The only thing this would accomplish is to rule out the possibility that the method returns the column with a different name for some strange reason. If there is no column that looks like it might be a different name for pkJudge, and your StoredProc is definitely returning the data correctly, then I still say there's something screwy with the DatabaseFactory class. Is anyone familiar enough with it to help? For example, what does it do if the value of pkJudge is NULL?


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, September 15, 2010 3:11 PM
  • technocrat et al,

    The column does exist in the result set being returned. Also, a point that I forgot to mention is that the error does not happen every time but happens frequently... again not always. If the column does not exist, I would assume that the error would happen all the time not randomly. This is what puzzles me about this issue.

    On some other forums, I read that other people had similar issues when the load on their system was high which is not also the situation in my case.

    Friday, September 17, 2010 2:23 AM
  • Hello guys,

    I tried to get rid of this error but this gave rise to a new error that says

    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Judge Name'.

     

    Below is the new code.

     

    Private Sub S_GetJudges(ByVal courtID As Integer)

     

    'Load the list of judges

     

    Dim JudgeSet As New DataSet

     

    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)

     

    JudgeDDL.SelectedValue = 0

    JudgeDDL.DataSource = JudgeDataTable.DefaultView

     

    JudgeDDL.DataBind()

     

    End If

     

    End Sub

    The stored procedure SQL that is executed is

    SELECT

     

    pkJudge,[Judge Name] FROM Judges

    WHERE

     

    ClientKey=@ClientKey AND fkCourt=@fkCourt

    Union

    Select

     

    0 as pkJudge, '(Select a Judge)' as [Judge Name]

    order

     

    by pkJudge asc

    Now how to resolve this error?

    Monday, September 20, 2010 5:36 PM
  • Sony ... since no one is helping you out, I figured I'd give this a little more thought and came up with something else for you to look at:

    In the DataSet that's returned, are you sure that JudgeSet.Tables(0) is really the DataTable you want? Try setting a breakpoint after the DataSet gets filled (on this line):

    JudgeDataTable = JudgeSet.Tables(0)

    Then, hover your mouse over the JudgeSet and you should be able to open the DataSet viewer (or whatever the heck it's called) ... take a look at all the Tables in your DataSet. You're obviously expecting Tables(0) to be the DataTable you want, but verify that it actually is (the fact that none of your Columns are in Tables(0) leads me to believe there are other DataTables). I could be wrong, but humor me ... ;0)


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, September 22, 2010 5:01 AM
  • Bonnie,

    I get this when I type in immediate window

    ?JudgeSet.Tables

    {System.Data.DataTableCollection}

    Count: 1

    IsReadOnly: False

    IsSynchronized: False

    Item: In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

    SyncRoot: {System.Data.DataTableCollection}

     

     

    Thursday, September 23, 2010 9:39 PM
  • Well, that rules out that idea.

    But again, I come back to the belief that the problem lies with the DatabaseFactory class. Surely someone here is familiar enough with it and/or the Enterprise Library to be able to help!!!

    @Sony, I'm not sure if there's a better Forum to post this question in, but I looked around and saw lots of questions about both DatabaseFactory and Enterprise Library in the ADO.NET Managed Providers Forum: http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/threads/  Maybe you'll  have better luck with this question there.

    Sorry to keep asking you to re-post the question!!


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Friday, September 24, 2010 9:14 PM
  • Thank you very much for your support Bonnie. I will re-post it.
    Monday, September 27, 2010 6:33 PM
  • I hope you get an answer in the other forum (doesn't look like you've gotten around to re-posting it yet).
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, September 29, 2010 4:58 AM