Question How to bubble sort data in ur MS Access database

Manny123

Member
Joined
Mar 6, 2012
Messages
16
Programming Experience
Beginner
Dim cn As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database genk.mdb;")
    Dim SQLString As String = "SELECT * FROM Products"
    Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(cn)
    Dim DataSet1 As New DataSet()
    Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
    OleDBConn1.Open()
    OleDbDataAdapter1.Fill(DataSet1, "Products")
    DataGrid_Sort.DataSource = DataSet1.Tables("Products")

Dim FLG as Boolean
 Dim EOA as Integer = B.lenth-1
 Dim Temp as Byte 
Do FLG = False
 For I = 0 To EOA = -1
 If B(I) > B(I+1) then
 Temp = B(I) B(I) = B(I +1) 
B( I +1) = Temp 
FLG = True
  End IF
 Next 
EOA = EOA -1
 Loop while FLG



Hi,
As you can see I am trying to use bubble sort to sort to sort my product details from my MS Access database. The buuble sort code is there and the data grid view code is there which retrives the product details in my databse. How would i link the two together so that when the user clicks the button it uses the bubble sort code to sort and view the product deatils in order of firstname or lastname etc?
 
Dim cn As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database genk.mdb;")
    Dim SQLString As String = "SELECT * FROM Products"
    Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(cn)
    Dim DataSet1 As New DataSet()
    Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
    OleDBConn1.Open()
    OleDbDataAdapter1.Fill(DataSet1, "Products")
    DataGrid_Sort.DataSource = DataSet1.Tables("Products")

Dim FLG as Boolean
 Dim EOA as Integer = B.lenth-1
 Dim Temp as Byte 
Do FLG = False
 For I = 0 To EOA = -1
 If B(I) > B(I+1) then
 Temp = B(I) B(I) = B(I +1) 
B( I +1) = Temp 
FLG = True
  End IF
 Next 
EOA = EOA -1
 Loop while FLG



Hi,
As you can see I am trying to use bubble sort to sort to sort my product details from my MS Access database. The buuble sort code is there and the data grid view code is there which retrives the product details in my databse. How would i link the two together so that when the user clicks the button it uses the bubble sort code to sort and view the product deatils in order of firstname or lastname etc?

Not exactly sure what you have in the DataGridView are all the details in the view IE: Firstname, LastName. If so why not just have the sort on the Header, that way you can get the DGV to do all the work instead of the code you have here.

Please give more details if I have the wrong end of the stick here.

Regards
 
The first block of code is viewing all the the product information on the DataGrid but i want to implement it so that when i click a button it sort the produts details in terms of what the user wants to sort through a combox i.e. the user clicks the combox and wants to sort the product IDs in order. How will I manipulate my bubble sort code to sort the product details shown in the data grid?

P.S. what is a DGV?

Thanks
 
The first block of code is viewing all the the product information on the DataGrid but i want to implement it so that when i click a button it sort the produts details in terms of what the user wants to sort through a combox i.e. the user clicks the combox and wants to sort the product IDs in order. How will I manipulate my bubble sort code to sort the product details shown in the data grid?

P.S. what is a DGV?

Thanks


Is all the data being put into one DataGridView and then you want to sort each product dependant on the users input?

P.S. Sorry about the abbreviation DGV is DataGridView.
 
Yes I want to sort each product dependant on the users input

Sorry I don't think you got what I said, Is all the data being put into 1 DataGridView? because if you are this makes it different than if you were using a couple of DataGridViews.
 
Back
Top