Column exists in ADO recordset?

04-19-2004, 04:50 AM
I have a ADO recordset with data. How do i check whether a column (named XXXX) is exists in the recordset before I retrieve the data from that column?

Any advice is appreciate. A mil thanks.

TheDutch IceMan
04-19-2004, 05:23 AM
You want to know if any data is in that column???

yourTextField.Text = IIF((statement), truepart, falsepart)

For example

txtClientPostalCode.Text = (IIF(IsNull(objRs!PostalCode)=False), objRs!PostalCode, "No postalcode available")

04-19-2004, 05:44 AM
if the field in not existing then This will give you an error. Isnull() can check only if that <field> is exists.

There is a way to check

If myrecordset(0).name="MyField" then

But U have to loop all fields here, which is not advisable or good design

Basicaly, if your designing is ok then this check is not neccessary. B4 reading the data from the recordset you shud know which firlds are available and not available

If U still want this then catch the error number (3265) and use a proper error handler

04-19-2004, 08:41 AM
No...why not just look for all field names in the recordset? Instead of looping all values, just loop .names. If you find the fieldName in question, it exists, if not, that field does not exist. Use a boolean variable to flag whether or not you get an true or false result.

When, you say looping all fields is not advisable or good design, how else do you plan on getting field names? Sure, if using SQL Server or Oracle you can query the system tables or using other methods of getting all field names. But, looping all the fields and returning their name property is just as valid as looping a recordset until EOF, returning all values. So, where is the bad practice in this?

This has nothing to do with proper design. Sometimes, the user might want to know all the fields in the database. Just because the developers KNOWS what fields are present, doesn't mean the end user will. If he was having some sort of data integrity issue, I would agree that this is a database design issue. But, simply having code to search for an existing field name is common AND NOT bad practice.

04-19-2004, 10:21 PM
I told him to t Loop the Fields names, NOT THE VALUES (Where Did I said to loop the Values ???-Check my example) But again Looping the field names are not sounds as a good practice. Assume that there are 30 Fields in a table and you are going to read the data one by one. If U loop the fields names to find the Column, U have to loop each time, which takes unneccesary time consumption.

Developer should know at least fields names. without knowing the field name How can a developer develop a Client-Server Application ? Im not saying that Developer should know all Database related stuffs. But At least he should know the fields name.

Why End user question is coming here ? Do U want End users to develop a system rather than using ? End user is end user. No one expects him to do programing. Having integrity issue a system problem and I never ask end-user to check the dB fields. Proper error hadler and messages can make end user clear

04-20-2004, 05:00 AM
I've worked on several applications involving databases with 100s of fields in each table. (Maybe bad database design but that's not the issue.) There are lots of times when you have to loop through the field names, including to check whether a field is there or not. E.g. all the tables apart from one might have a particular field and it would be very inefficient to have to store which is the one table without the field. Much easier to write a couple of lines of code to find out by iterating the field names. If you're designing a query builder for the end user you have to show them all the possible fields to choose from, and you've got no choice other than to iterate the field names.

04-20-2004, 07:19 AM
But U have to loop all fields here, which is not advisable or good design

Basicaly, if your designing is ok then this check is not neccessary. B4 reading the data from the recordset you shud know which firlds are available and not available

This is your exact quote. And yes, I stick by my point, and you are making no sense. Unnecessary time consumption, what are you talking about? So, is looping a recordset until EOF BAD practice too :)? Loop until the end of a recordset field count takes milliseconds. And where does he say in his post that HE DOES NOT know his field names? You are just assuming this.

And I said my reply (maybe YOU should read my post again) that looping the name count AND looping for values is both fine practice. Would the end user want to know the names of the fields in the application ABSOLUTELY :). ALL Database engines is there not a query builder? Hmmm...don't you need field names for this? Have you ever developed your own query builder, I have :). I helps to list all fields. Or, how about an automated report builder...have you ever done anything like this? I sure have. It helps here too to have a list of potential fields you can drag and drop onto your report. I can think of many reasons why you need to list field names within a database.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum