how to display multiple records in multiple textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harmony123
    New Member
    • Apr 2010
    • 8

    how to display multiple records in multiple textboxes

    I would like to display the multiple records in multiple textboxes
    Following is my tables and data:

    tblJan with these data:
    col id
    1
    2
    3
    col January
    10
    20
    30

    now i want to display the value 10 in one textbox and the value 20 in another textbox and so with the value 30 in another textbox..

    i am new in vb.net and a help would be greatly appreciated..tn x..
  • semomaniz
    Recognized Expert New Member
    • Oct 2007
    • 210

    #2
    Please show us what you have done? With out trying yourself you wont learn any thing. We all can write a piece of code and post it but the idea is to learn from mistakes. Give it a shot and then show us the error you get.

    here is what you can do.
    1. Read the data from the database
    2. use foreach loop to go through the data
    3. for each data create a text box and assign the value


    Hope this helps

    Comment

    • robjens
      New Member
      • Apr 2010
      • 37

      #3
      I guess it also depends on if you want to just read this data or actually update, insert and delete too (CRUD). Basically u can pick between typed and untyped DataSet or DataReader... Loop through the data and store the objects in a collection.

      Then you create a instance of the System.Windows. Forms class and add a textbox control to the controls collection for every column/value you find. But this has so many problems on the way, you don't want to take this road trust me. For example, how are you going to check what data type it is? Are you always going to take the textbox control or perhaps a checkbox if it's a boolean? Then you might need a Select Case routine to add the correct control to the form. Where are you going to validate the values? Who controls the database itself and prevents someone from adding a 13, 14 or 15th month? Etc etc.

      I guess you wish to make a continuous form like in ACC 2003 but no need to do that in .NET. You have inheritance and datagridviews. I suggest, if you use Visual Studio, you try out the wizards that MS gives you. It's easy to make detail views like the wizard in Access (form view) or display as a table in the DataGridView control

      Like semomaniz, some more info would be nice :P

      Comment

      • harmony123
        New Member
        • Apr 2010
        • 8

        #4
        hi!..tnx 4 ur reply..these is what i've come up too based on what i've read..but with these codes i cnt display ol d rows in my database..examp le if i have 3 current data on my database then i should display those on 3 textboxes also..
        Code:
         If dt.Rows.Count < 1 Then
                    MsgBox("Record not Found", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Search")
                End If
                Me.BindingContext(dt).Position = Me.BindingContext(dt).Count - 1
                Dim dr As SqlDataReader
                dr = cmd.ExecuteReader
        
                While dr.Read
        
                    TextBox1.Text = dr.GetValue(0)
                    TextBox2.Text = dr.GetValue(1)
                     textbox3.text=dr.GetValue(2)
        
                End While
        Last edited by Frinavale; May 4 '10, 03:24 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

        Comment

        • harmony123
          New Member
          • Apr 2010
          • 8

          #5
          by the way here is my sql query..
          Code:
          cmd.Connection = conn
                  conn.Open()
                  cmd.CommandText = "SELECT tblJan.january+tblJan_Abra.january FROM tblJan,tblJan_Abra"
          Last edited by Frinavale; May 4 '10, 03:24 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

          Comment

          Working...