5 Replies - 4810 Views - Last Post: 16 February 2011 - 08:42 PM Rate Topic: -----

#1 Inope  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-February 11

Sorting Using Combo box, Text box & Data grid.

Posted 15 February 2011 - 10:58 PM

This is the Kind of sorting I want to do...to select different fields
and click the button search to display info in the data grid.
Also is not a must that i must fill all field to sort...i might choose 2 or 3 field and do my sorting by clicking the search button. The combo box contains all the fields in my database. (E.g My Screen shot display how it look like)

Below is my snap shot of my page i uploaded.
Please comment any CODE provided along with the combo box and text box and the search field
for me to understand clearly. i'm using Access Database. thanks.
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Sorting Using Combo box, Text box & Data grid.

#2 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Sorting Using Combo box, Text box & Data grid.

Posted 16 February 2011 - 02:09 AM

well no one will just give you code. you will have to try it yourself and if you get stuck we can help..

anyhow, allowing the user to sort by more than 2 columns will end up in confusion. trust me i have 90 users on my system and that caused havoc. also in what sort order would they be in, what column is first and what is second etc... You can build your querry to sort the data the way you want when fetching the records. That should be easy enough.
Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Sorting Using Combo box, Text box & Data grid.

Posted 16 February 2011 - 05:31 AM

Not sure about how you're handling the database but it would appear to me that you could build an sql statement and a separate order by clause based on the fields you want to sort by. Then just append the order by clause to the end of your statement.
Was This Post Helpful? 1
  • +
  • -

#4 Guest_Inope*


Reputation:

Re: Sorting Using Combo box, Text box & Data grid.

Posted 16 February 2011 - 08:53 AM

Please I have tried different CODE to make it work, yet is not working...Please i have dead line for this work...Please if u can help please...do...I will appreciate it...I want a fully understand code that has comment...not that i didn't try how to make it work...have errors...I want a code explain along with the combo box and the textbox & data grid...to show how i can apply it...to my work Thank you God Bless.
Was This Post Helpful? 0

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Sorting Using Combo box, Text box & Data grid.

Posted 16 February 2011 - 09:15 AM

Well, you see... There's a large problem here, Of all the people who frequent this board, I'm not sure that any of us are Psychic. So maybe if you post the code you've written to attempt this, we can be a little more helpful in the completion of your task. Without code, we cannot help you and we won't write your program for you.

This post has been edited by CharlieMay: 16 February 2011 - 09:16 AM

Was This Post Helpful? 0
  • +
  • -

#6 Inope  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 07-February 11

Re: Sorting Using Combo box, Text box & Data grid.

Posted 16 February 2011 - 08:42 PM

I'm trying to use this code...But i cannot use... because it was written on SQL Connection...I'm using ACCESS DB. As u can see in my previous snap shop i have five combo box, Five Text box and Data grid. My Table name is Mission. I have done other work my self which is working very fine...like export to excel did it myself...this is the only one giving me problem. Please i want a clear CODE with comment on how to use this code along with my five combo box and text box...And inside my textbox contain all the field name in my DB and the text box user type wht he's looking for and click on the search key to display the records on the data grid and do the sorting...Please I do appreciate your helping hand....Thank U.

Select Case cmbCriteria.Text
'***************************************************************'
Case "ID NUMBER"
Dim objAdap As SqlCeDataAdapter
Dim objDt As New DataTable

strConn = "Data Source=" & _systemdb
objConn = New SqlCeConnection(strConn)
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE IdNumber LIKE '" & txtSearch.Text & "%' ORDER BY idNumber", objConn)
objAdap = New SqlCeDataAdapter(objComm)

Try
objAdap.Fill(objDt)

If objDt.Rows.Count > 0 Then
dgPersonal.DataSource = objDt
objDt = New DataTable
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE IdNumber=" & dgPersonal.Rows(0).Cells(0).Value.ToString(), objConn)
objAdap = New SqlCeDataAdapter(objComm)
objAdap.Fill(objDt)


Else
MsgBox("No Record Found.", MsgBoxStyle.OkOnly, "Personal Information")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
End Try
'***************************************************************'
Case "LAST NAME"
Dim objAdap As SqlCeDataAdapter
Dim objDt As New DataTable

strConn = "Data Source=" & _systemdb
objConn = New SqlCeConnection(strConn)
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE LastName LIKE '" & txtSearch.Text & "%' ORDER BY LastName", objConn)
objAdap = New SqlCeDataAdapter(objComm)

Try
objAdap.Fill(objDt)

If objDt.Rows.Count > 0 Then
dgPersonal.DataSource = objDt
objDt = New DataTable
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE IdNumber=" & dgPersonal.Rows(0).Cells(0).Value.ToString(), objConn)
objAdap = New SqlCeDataAdapter(objComm)
objAdap.Fill(objDt)


Else
MsgBox("No Record Found.", MsgBoxStyle.OkOnly, "School Information")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
End Try
'***************************************************************'
Case "FIRST NAME"
Dim objAdap As SqlCeDataAdapter
Dim objDt As New DataTable

strConn = "Data Source=" & _systemdb
objConn = New SqlCeConnection(strConn)
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE FirstName LIKE '" & txtSearch.Text & "%' ORDER BY FirstName", objConn)
objAdap = New SqlCeDataAdapter(objComm)

Try
objAdap.Fill(objDt)

If objDt.Rows.Count > 0 Then
dgPersonal.DataSource = objDt
objDt = New DataTable
objComm = New SqlCeCommand("SELECT * FROM tblPersonal WHERE IdNumber=" & dgPersonal.Rows(0).Cells(0).Value.ToString(), objConn)
objAdap = New SqlCeDataAdapter(objComm)
objAdap.Fill(objDt)


Else
MsgBox("No Record Found.", MsgBoxStyle.OkOnly, "School Information")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
End Try
End Select
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1