Populating Textboxes from Database

Results 1 to 2 of 2

Thread: Populating Textboxes from Database

  1. #1
    Join Date
    Dec 1969

    Default Populating Textboxes from Database

    I have database with date as the key elements and a few other columns like in the example below<BR><BR><BR>DATE Val1 Val2 Val3 Val4<BR>____________________________________<BR><B R>Jan 1 12 43 12 ABS <BR>Jan 2 32 67 44 rhg My DATABASE<BR>Jan 5 32 76 45 J8hjk<BR>.<BR>.<BR>.<BR><BR>My ASP.Net form consists of textboxes for each of those values.<BR>I want to populate these text boxes from the database. The ones for which there isn&#039;t any date are to be kept empty as in the figure below<BR><BR><BR> Jan1 Jan2 Jan3 Jan4 Jan5 Jan6<BR> 12 32 32<BR> 43 67 44 MY FORM <BR> 12 44 45<BR> ABS rhg J8hjk<BR><BR><BR>How can I do so? Please Advise me <BR><BR>- I would like to use OLEDB<BR>- I am working with VBscript<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Populating Textboxes from Database

    I&#039;d start by redesigning your Database.<BR><BR>Something more like:<BR><BR>ID &#124 Value &#124 Date<BR>1 &#124 12 &#124 Jan1<BR>2 &#124 43 &#124 Jan1<BR>3 &#124 12 &#124 Jan1<BR>4 &#124 ABS &#124 Jan1<BR>5 &#124 32 &#124 Jan2<BR>etc...<BR><BR>(You may or may not need the ID, depending if you need a Primary Key)<BR><BR>Then look up how to pull all rows from your DB into a Table or DataSet. There&#039;s tons of articles out there on how to do this.<BR><BR>Next, I&#039;d create a DataView with this table. Filter the DataView by Date. (dvwDataView.RowFilter="Date=&#039;1/1/2004&#039;")<BR><BR>Now you have a subset of the original data representing the data for the specified date.<BR><BR>Loop through those and put each into a Textbox...<BR>for i = 0 to dvwDataView.Count<BR> txtJan1A.Text = dvwDataView(i)("Value") &#039;Not positive of the syntax for VB<BR> txtJan1B.Text = ...<BR> txtJan1C.Text = ...<BR> txtJan1D.Text = ...<BR>next<BR><BR>That should do what you are looking to do.<BR><BR>However, once you&#039;ve got that all working I&#039;d move to create this stuff dynamically. It sounds like your page is static right now. For example, you could specify a date range, grab all data within that range. Loop from the begining of the range to the end, filtering a DataView with each iteration. With each iteration in that loop you should do the DataView loop (i.e. for i = 0 to dvwDataView.Count) and create a TextBox on the fly and add it to your page. <BR><BR>Hope this helps get you started...<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts