In MFC - with ODBC - How to select only few columns from a table
- From: Florin <Florin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 Oct 2006 12:03:02 -0700
Hello!
My scenario is:
I made a project in Visual C++.NET (2003) - MFC with ODBC. CDatabase and
CRecordset.
In Sql Server 2000 I made a table Tab1 with 10 columns for sample.
Nr_doc, Data_doc, Val_1, Val_2, Val_3, Val_4, Val_5, Val_6, Val_7 and
Val_Tot
In Visual C++ - MFC I want to select only 2 columns from this table use
CRecordset - Open()....
In this moment my code is (for sample):
CDatabase dbDateServ;
CRs_Tab1* rsTab; //CRs_Tab1 - is a class MFC - ODBC -
Consummer
//bind to table Tab1
CString szConectSql;
szConectSql = "ODBC; DSN=SQL_Server; UID=sa; PWD=florin; DATABASE=DateServ";
dbDateServ.Open(szConectSql);
rsTab = new CRs_Tab1(&dbDateServ);
rsTab->Open(CRecordset::snapshot, "SELECT * FROM Tab1");
......... other commands etc
rsTab->Close();
delete rsTab;
dbDateServ.Close();
In this situation in my recordset are selected all columns from the table
Tab1.
But I don't this thing. I want in rsTab->Open(CRecordset::snapshot, "....");
to execute the comand
SELECT Nr_doc, Data_doc FROM Tab1.
I want to select only 2 columns from my table in this recordset.
If I will write
rsTab->Open(CRecordset::snapshot, "SELECT Nr_doc, Data_doc FROM Tab1");
or
rsTab->Open(CRecordset::snapshot, "SELECT Nr_doc AS Nr_doc, Data_doc AS
Data_doc FROM Tab1");
It's not OK because appear an error "Invalid descriptor index."
My question is How to do this thing?
Thank You very much!
Please!!!!!!
.
- Follow-Ups:
- Re: In MFC - with ODBC - How to select only few columns from a table
- From: Scot T Brennecke
- Re: In MFC - with ODBC - How to select only few columns from a table
- Prev by Date: Finding a List of ODBC DSN's from a COM object
- Next by Date: Cascade Updates/Deletes & Auto Increment Primary Key with Linked Table
- Previous by thread: Finding a List of ODBC DSN's from a COM object
- Next by thread: Re: In MFC - with ODBC - How to select only few columns from a table
- Index(es):