Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the field list from my Recordset

Status
Not open for further replies.

marcustaylor

Programmer
May 11, 2000
1
GB
I have a VB Program and I want to search a table, I want to choiose what field to search, This field will be choosen from a dropdown box, How do I populate this box with all the field names in a table in real time?
 
That would depend a lot on which RDBMS you are using.
 
what are you using to build a recordset? dao? <p>Mike<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>Please don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
I did this test in ASP using ADO:<br><br>---<br>dim rs<br>set rs = server.CreateObject(&quot;ADODB.recordset&quot;)<br><br>rs.Open &quot;TABLE&quot;,activeconnection<br><br>Response.write rs.Fields(0).Name<br>---<br><br>0 is the first field. You could put this in a loop. You would, however, need to determine the number of fields in the table so you could use a FOR...NEXT loop to put in your dropdown box.
 
Here is some code that I used to do something similar except I was putting the field names as a table header.<br><br>&lt;% <br>sub query2table(inputquery, inputDSN)<br>&nbsp;&nbsp;&nbsp;dim conntemp, rstemp<br>&nbsp;&nbsp;&nbsp;set conntemp=server.createobject(&quot;adodb.connection&quot;)<br>&nbsp;&nbsp;&nbsp;conntemp.open inputDSN<br>&nbsp;&nbsp;&nbsp;set rstemp=conntemp.execute(inputquery)<br>&nbsp;&nbsp;&nbsp;howmanyfields=rstemp.fields.count -1%&gt;<br>&nbsp;&nbsp;&nbsp;&lt;table border=1&gt;&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&lt;% Put Headings On The Table of Field Names<br>&nbsp;&nbsp;&nbsp;for i=0 to howmanyfields %&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&lt;b&gt;&lt;%=rstemp(i).name%&gt;&lt;/B&gt;&lt;/TD&gt;<br>&nbsp;&nbsp;&nbsp;&lt;% next %&gt;<br>&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br>&nbsp;&nbsp;&nbsp;&lt;% ' Now lets grab all the records<br>&nbsp;&nbsp;&nbsp;do while not rstemp.eof %&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;% for i = 0 to howmanyfields<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thisvalue=rstemp(i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If isnull(thisvalue) then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thisvalue=&quot;&nbsp;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if%&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td valign=top&gt;&lt;%=thisvalue%&gt;&lt;/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;% next %&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%rstemp.movenext<br>&nbsp;&nbsp;&nbsp;loop%&gt;<br>&nbsp;&nbsp;&nbsp;&lt;/table&gt;<br>&nbsp;&nbsp;&nbsp;&lt;%<br>&nbsp;&nbsp;&nbsp;rstemp.close<br>&nbsp;&nbsp;&nbsp;set rstemp=nothing<br>&nbsp;&nbsp;&nbsp;conntemp.close<br>&nbsp;&nbsp;&nbsp;set conntemp=nothing<br>end sub%&gt;<br><br><br><br><br>you can use the recordset.field.count&nbsp;&nbsp;to determine the number of fields in the table.<br>then use a loop and the recordset(i).name to grab the anem of each field. Where i is the counter in the loop. This was using ADO and ASP.<br><br><br><br>Seth<br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top