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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CRecordSet::GetFieldValue 2

Status
Not open for further replies.

Sridharan

Technical User
Dec 3, 2001
523
IN
Hello All,

I'm having a CRecordset derived class. Can anyone help me how to retrieve the value returned by the SQL Query. I don't want to use CFieldExchange method as my Database Table will change dynamically. When I do GetFieldValue(index, szString) I'm getting only first 25 characters into szString. How to get the entire column value and also how to find how many records were returned by the query.

Many a thanks!
Sridharan
 
what is the SQL type of the field according to CODBCFieldInfo and CRecordset::GetODBCFieldInfo?

also post your "relevant" code containing the GetFieldValue call.

-pete
 
Hi Pete,

Thanks for your reply. I did solve that problem. It is due to the backend data problem. Also I have few more questions. Hope you can help me out.

1. How to get the no of rows returned by the query in the RecordSet. I tried GetRecordCount() but it always gives me one.

2. How do one find the datatype of the field being retrieved. If I pass to GetFieldValue the field no and a CString variable it doesn't get data for all the field types from SQL Server. How to write a GetFieldValue function which will get the value of the column irrespective of the column type.

3. Is it possible to read the resultset in batches i.e. if the rows returned by the query is say some millions instead of getting the entire resultset and reading which will take considerable amount of time how do one get it in batches. Also is it possible to do bulk read.

I would appreciate your answers/tips!

Thanks
Sridharan
 
1. The number of records property is the highest number of records you were in so far. Since the recordset pointer points to the first record after retrieval (if any records) that will be 1. You'll have to move to the last record in the set to retrieve the actual number of records in the set.

2. Send in a DBVariant instead of a string with a fieldtype of DEFAULT_FIELD_TYPE. Examine the m_dwType member of the DBVariant and assign its value to a proper variable.

3. Check out 'SetRowsetSize' for that. However, I think thid only works in conjunction with CFieldExchange, which you didn't want to use.
Greetings,
Rick
 
Hi Rick,

Thanks a bunch for your tips.

1. I did manage to get the no of rows fetched by GetRecordCount() function.

2. I tried passing a CDBVariant variable with DEFAULT_FIELD_TYPE but get an assertion failure when I try to read a text value.

3. I really didn't get your thoughts. My problem is if I have a huge table say million or more rows how to effectively get the results without taking too much of system resources and also if in mid way the program is stopped is it possible to continue from where it let off something like Download Manager kinda thing.

Thanks
Sridharan
 
2. Did you check if its actually a text value in the DBVariant?

3. I have never done what you want, but by browsing to the 'SetRowsetSize' you will be directed to how to do what you want (at least that's what I think). If I understand correctly it enables you to execute multiple fetches with a restricted number of rows in the resultset. You'll have to test and play with it a little I guess...
Greetings,
Rick
 
Rick is correct. You can't just read a string from a VARIANT. In otherwords if the TYPE of the VARIANT is not a string type you will have to do the transformation to a string yourself. The VARIANT does not do that for you.

If you have never worked with variant's before you should study them before trying to use them.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top