Specifying "Sort Order"

Results 1 to 2 of 2

Thread: Specifying "Sort Order"

  1. #1
    Join Date
    Dec 1969

    Default Specifying "Sort Order"

    Thanks for the help you gave me in creating my dataset. Now I think I&#039;ve sorted my data into a DataView, but I&#039;m getting an error on the first "Find" statement: "Find finds a row based on a Sort order, and no Sort order is specified." It&#039;s highlighting the statement, "intFindIndex=dvwTraits.Find(intTraitNo)" My code is below. Would you, please, help me again?<BR><BR>Sub Page_Load(sender as Object, e as EventArgs)<BR> Dim intTraitNo as Integer, _<BR> intQuestNo as Integer, _<BR> intFindIndex as Integer<BR><BR> Dim dstCompatibility as System.Data.DataSet, _<BR> conCompatibility as System.Data.OleDb.OleDbConnection, _<BR> dadCompatibility as System.Data.OleDb.OleDbDataAdapter, _<BR> dtblTraits as System.Data.DataTable, _<BR> dtblQuestions as System.Data.DataTable, _<BR> dvwTraits as System.Data.DataView, _<BR> dvwQuestions as System.Data.DataView, _<BR> arrQuestKey(1) as Object<BR><BR> Dim connectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0; " _<BR> & "Ole DB Services=-4; Data Source=C:My ASPNet Web SiteCompatibility.mdb"<BR><BR> intTraitNo = Val (lblTraitNo.Text)<BR> intQuestNo = Val(lblQuestNo.Text) + 1<BR><BR> &#039;Is cached "Traits" dataset available?<BR> dvwTraits = Cache ("Traits")<BR> dvwQuestions = Cache("Questions")<BR> If (dvwTraits Is Nothing) Or (dvwQuestions Is Nothing) Then<BR><BR> &#039;Retrieve Traits & Questions from database<BR> dstCompatibility = New System.Data.DataSet()<BR> conCompatibility = New System.Data.OleDb.OleDbConnection(connectionString )<BR><BR> Dim SQL as String<BR> SQL = "SELECT trait_no, trait_desc FROM tbl_traits WHERE trait_no &#062;= " _<BR> & CStr(intTraitNo)<BR> dadCompatibility = New System.Data.OleDb.OleDbDataAdapter(SQL,conCompatib ility)<BR> conCompatibility.Open()<BR> dadCompatibility.Fill(dstCompatibility, "Traits")<BR> SQL = "SELECT trait_no, quest_no, question FROM tbl_questions WHERE " _<BR> & "trait_no &#062;= " & CStr(intTraitNo)<BR> dadCompatibility.SelectCommand = New System.Data.OleDb.OleDbCommand( _<BR> SQL,conCompatibility)<BR> dadCompatibility.Fill(dstCompatibility, "Questions")<BR> conCompatibility.Close()<BR><BR> &#039;Add parent/child relationship<BR> dstCompatibility.Relations.Add("Traits_Questions", _<BR> dstCompatibility.Tables("Traits").Columns("trait_n o"), _<BR> dstCompatibility.Tables("Questions").Columns("trai t_no"))<BR><BR> &#039;Create dataviews<BR> dvwTraits = dstCompatibility.Tables("Traits").DefaultView()<BR > dvwTraits.Sort = "trait_no"<BR> dvwQuestions = dstCompatibility.Tables("Questions").DefaultView() <BR> dvwQuestions.Sort = "trait_no, quest_no"<BR><BR> &#039;Store dataviews in memory<BR> Cache ("Traits") = dvwTraits<BR> Cache ("Questions") = dvwQuestions<BR> End If<BR><BR> If intQuestNo &#062; 22<BR> &#039;Next trait<BR> intTraitNo &= + 1<BR> If (intTraitNo &#062; 12) Then<BR> &#039;All traits completed<BR> &#039;---------- Add code<BR> EndOfQuestions()<BR> Return<BR> Else<BR><BR> btnSubmit.Text = "OK"<BR> btnQuit.Visible = False<BR> btnQuit.Enabled = False<BR><BR> &#039;Find trait<BR> lblTraitNo.Text = CStr (intTraitNo)<BR> intQuestNo = 1<BR> tbxTraitScore.Text = "0"<BR> intFindIndex = dvwTraits.Find (intTraitNo)<BR> If intFindIndex = -1 Then<BR><BR> lblErr.Text = "Data problem - Trait not found!"<BR> CannotContinue()<BR> Else<BR><BR> lblTraitName.Text = dvwTraits (intFindIndex).Row("trait_name")<BR> End If<BR> End If<BR> End If<BR><BR> &#039;Find questions in cached dataset<BR> lblQuestNo.Text = CStr(intQuestNo)<BR> arrQuestKey(0) = intTraitNo<BR> arrQuestKey(1) = intQuestNo<BR> intFindIndex = dvwQuestions.Find (arrQuestKey)<BR> If intFindIndex = -1 Then<BR><BR> lblErr.Text = "Data problem - Question not found!"<BR> CannotContinue()<BR> Else<BR><BR> lblQuestion.Text = dvwQuestions (intFindIndex).Row("question")<BR> If intQuestNo = 22 Then<BR> &#039;Last question for this trait<BR> btnSubmit.Text = "Save & Continue"<BR> btnQuit.Visible = True<BR> btnQuit.Enabled = True<BR> End If<BR> End If<BR> End Sub<BR>

  2. #2
    Join Date
    Dec 1969

    Default Are you sure...

    ...that the code <BR> dvwTraits.Sort = "trait_no"<BR>is being executed, before you attempt the Find? Because that line is inside an IF so if it is never reached, then the error message would make sense.<BR><BR>Why not, just in case, put that line just ahead of your FIND line?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts