Hi!
So, I have a dataset which is filled with data after a mysql SELECT Statement, I'll call the dataset dsResults.Tables("Results")

Inside the dataset is data that I want to be filled into their respective text boxes. The columns in the dataset are expected to vary, for example, sometimes it may include the month Oct,Nov,Dec and sometimes I will include other months (just an example. Now each "month" in the dataset goes to respective textbox in the form. I will put all textboxes in the form and then hide all of them. After the Select statement executes and fill the dataset with data, I will then unhide the textboxes which their columns exists in the dataset and fill them with respective data from the dataset, while leaving other textboxes hidden.

I think may be it may be possible to do this with a loop? A loop that can read contents of the dataset and then unhide the respective textboxes (this is what I don't know how to do) and fill these textboxes with the data from their dataset.

Any idea please?
Thanks.

Recommended Answers

All 5 Replies

You can go through the tables column name . By control flow you can show the textboxs of the respective months.

You could also use a Dictionary(Of String,TextBox). The name of the column as the index of the Dictionary will return that specific TextBox that you can set or get any of its properties.

The report to be produced is a student academic report that shows student's scores for a particular semester. As an example, one student may be taking (science, math, english) while another takes (science, arts, french) I can pull their scores from the database to a dataset but then, the report form for student one has to show Labels & TextBoxes like

  science:
  math:
  english:

While the other student's report form has to show only the textboxes from his courses, that's

 science:
  arts:
  french:

So here, the challenge is to decide which textboxs (and labels) to show on the form, and then I will put values from the dataset in them.

I was thinking; If I put Label1,Label2,Label3...........Label10 in the form and hide them. Is there a way then after I get the set of courses a student takes, say (science,math,english) to kinda loop through them and do like Label1.Text =science, Label2.text = "math", label3.text = "english" after I un-hide them?

Please post your codes how far you did.

Assuming the textboxes' names are the same as the column names, in your form, set up the dictionary:

Public courses As New Dictionary(Of String, TextBox)
Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.
    For Each tb As TextBox In Me.Controls.OfType(Of TextBox)
        courses.Add(tb.Name, tb)
    Next
End Sub

Then when you get the column names representing the courses the student has taken you can assign the value to the textbox:

Label1.text = ColumnName
courses(ColumnName).Text = Score
courses(ColumnName).Visible = True

This should give you a clearer idea on how to proceed. If not you will probably need to show examples of the code you're using to get the column names and scores.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.