can someone give me an idea on how to do this scenario:
i have an ms access database table named IssuedBooks, this table has a primary key "IDNumber" which is set into AutoNumberField. In my vb, i have a form with 20 textboxes (10 for txtBorrowerNames, 10 for txtTotalNumber of BorrowerNames). what i want to happened is that when i clicked a button txtBorrowerName1 will be filled with 1 BorrowerName and its corresponding txtTotalNumber1 will be filled with the total number that, that name is repeated in that table.
for example,
KAREN is repeated 30x; txtBorrowerName(KAREN) = txtTotalNumber(30)
ANA is repeated 20x; txtBorrowerName(ANA) = txtTotalNumber(20)
DEAN is repeated 10x; txtBorrowerName(DEAN) = txtTotalNumber(10)
i can't contruct any codes yet, because i'm a bit confused on what procedure i'll do; whether to use arrays or just a select query with COUNT, DISTINCT and GROUP BY options.
Group and Count datarecords from database
Page 1 of 14 Replies - 994 Views - Last Post: 05 August 2012 - 10:16 PM
Replies To: Group and Count datarecords from database
#2
Re: Group and Count datarecords from database
Posted 05 August 2012 - 09:09 PM
Design-wise a DataGridView would work great for this. Make a query and display the results as the datasource.
You need to replace the parts of the above query with your data model.
Dim query = From rec As Record In Library Where rec.name = "KAREN" dgv.Datasource = query
You need to replace the parts of the above query with your data model.
#3
Re: Group and Count datarecords from database
Posted 05 August 2012 - 09:42 PM
i've also thought that having dgv would be easier, but in this form i did't plan placing a dgv. is it possible just to use a textbox? and one more thing, with regards to this, , what if i don't have a specific rec.name, i mean karen, ana and dean where just examples so txtBorrowerNames would primarily depends on the greatest Total number that the names are repeated. If "karen" has the greatest number of repeated name then she will be placed on the first txtBorrowerNames. Can you follow me? pardon if i can't explain it clearly. just to clarify what's this for, this will be the basis of a pie graph that i created in the same form that these textboxes belong.
Quote
Where rec.name = "KAREN"
#4
Re: Group and Count datarecords from database
Posted 05 August 2012 - 10:10 PM
i've solved it now.. thanks for your idea.
here is the codes i used:
i still used datagridview, just like what you said, and in order to achieve what i desired, i just hide it upon load form.
thank you.
here is the codes i used:
Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pie.Click
con.Open()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
da = New OleDbDataAdapter("Select TOP 10 Borrower, COUNT(Borrower) as Total from IssueBooks GROUP BY Borrower ORDER BY COUNT(Borrower) desc", con)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
txtName1.Text = DataGridView1.Rows(0).Cells("Borrower").Value
txtNum1.Text = DataGridView1.Rows(0).Cells("Total").Value
con.Close()
End Sub
i still used datagridview, just like what you said, and in order to achieve what i desired, i just hide it upon load form.
Private Sub PieGraph_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Hide()
End Sub
thank you.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|