Visual Studio Development Bookmark and Share   
 index > Developer Documentation and Help System > Walkthroughs for Visual Studio 2008
 

Walkthroughs for Visual Studio 2008

Walkthrough: Creating a Rich Client Application with MFC

This example uses OLE DB to connect to a database. It is the first walkthrough on the list.

From the OLE DB Provider(s) list box, click the Microsoft OLE DB Provider for SQL Server item and click Next

The user is directed to copy the follwing block of code intoOnInitialUpdate method of the CMyProjectView class.


HRESULThr=S_OK;
TCHARszAuthor[80];
CMyProjectSet&dbset=GetDocument()->m_MyProjectSet;
[db_command(name="cmd",source_name="dbset",hresult=hr)
{
SELECTau_lname
([bindto]szAuthor)
FROMAUTHORS
}];
while(cmd.MoveNext()==S_OK)
m_DataList.InsertString(-1,szAuthor);


However at compile time the code generates errors

Error1error C2143: syntax error : missing ']' before '{'...\myproject\myprojectview.cpp94MyProject
Error2error C2440: 'initializing' : cannot convert from 'HRESULT' to 'const char *'...\myproject\myproject\myprojectview.cpp93MyProject
Error3error C2143: syntax error : missing ';' before '{'...\myproject\myproject\myprojectview.cpp94MyProject
Error4error C2065: 'SELECT' : undeclared identifier...\myproject\myprojectview.cpp96MyProject
Error5error C2146: syntax error : missing ';' before identifier 'au_lname'...\myproject\myproject\myprojectview.cpp96MyProject
Error6error C2143: syntax error : missing ')' before '['...\myproject\myproject\myprojectview.cpp96MyProject
Error7error C2065: 'bindto' : undeclared identifier....\myproject\myproject\myprojectview.cpp96MyProject
Error8error C2146: syntax error : missing ';' before identifier 'szAuthor'...\myproject\myproject\myprojectview.cpp96MyProject
Error9error C3861: 'au_lname': identifier not found...\myproject\myproject\myprojectview.cpp96MyProject
Error10error C2059: syntax error : ')'...\myproject\myproject\myprojectview.cpp96MyProject
Error11error C2146: syntax error : missing ';' before identifier 'FROM'...\myproject\myproject\myprojectview.cpp97MyProject
Error12error C2065: 'FROM' : undeclared identifier...\myproject\myproject\myprojectview.cpp98MyProject
Error13error C2146: syntax error : missing ';' before identifier 'AUTHORS'...\projects\myproject\myproject\myprojectview.cpp98MyProject
Error14error C2065: 'AUTHORS' : undeclared identifier...\myproject\myproject\myprojectview.cpp98MyProject
Error15error C2143: syntax error : missing ';' before '}'...\myproject\myproject\myprojectview.cpp98MyProject
Error16error C2143: syntax error : missing ';' before ']'...\myproject\myproject\myprojectview.cpp98MyProject
Error17error C2065: 'cmd' : undeclared identifier...\myproject\myproject\myprojectview.cpp100MyProject
Error18error C2228: left of '.MoveNext' must have class/struct/union...\myproject\myproject\myprojectview.cpp100MyProject
Error19fatal error C1903: unable to recover from previous error(s); stopping compilation....\myproject\myproject\myprojectview.cpp100MyProject

If you revise this code to refit the command into the db_command line by using 'command =' and change the HRESULT hr; to char *hr; it will remove most of the errors. However the errors 17 and 18 will remain. The code does not appear to be supported in the compiler. Even though db_command dynamically creates the class 'cmd' the compiler does not recognize it and inthe while
(cmd.MoveNext()==S_OK) statement cmd is "undeclared"

The documentation on the db_command statement in 2008 seemed so scarce that it could only be understood by going back to 2003 and even there not so good. I personally was very dissapointed with this as in seems to indicate abandonment of some basic stuctures in VS 2008.


P4 3.0 GH, 2GB RAM, GeForce FX 5200 256MB, DSL VS 2008 Pro, SQL Server 2005 Developer




P4 3.0 GH, 2GB RAM, GeForce FX 5200 256MB, DSL VS 2008 Pro, SQL Server 2005 Developer
codeWhitler  Wednesday, June 04, 2008 10:24 AM
Try using:

HRESULT

hr = S_OK;

TCHAR

szAuthor[80];

CMyProjectsSet

&dbset = GetDocument()->m_MyProjectsSet;

[db_command(command= "SELECT au_lname ([bindto]szAuthor) FROM AUTHORS", name="cmd", source_name="dbset", hresult="hr")];

while (cmd.MoveNext () == S_OK )

m_DataList.InsertString (-1, szAuthor);

Magilla

magilla_48138  Friday, September 12, 2008 12:34 PM
I revised the above to be:

-----------------------------------------------

HRESULT hr = S_OK;

TCHAR szAuthor[80];

CMyProjectSet &dbset = GetDocument()->m_MyProjectSet;

[db_command(command= "SELECT au_lname ([bindto]szAuthor) FROM AUTHORS", name="cmd", source_name="dbset", hresult="hr")];

while (cmd.MoveNext () == S_OK )

m_DataList.InsertString (-1, szAuthor);

-----------------------------------------------

This appeared to compile and run displaying the authors in the list box.

This was also my first walkthrough and abit agravating that syntax was incorrect.

Drumahh  Wednesday, October 01, 2008 12:27 AM
Thanks! that worked for me.
codeWhitler

P4 3.0 GH, 2GB RAM, GeForce FX 5200 256MB, DSL VS 2008 Pro, SQL Server 2005 Developer
codeWhitler  Thursday, October 02, 2008 5:56 PM

Spent few hours trying to figure out exact same problem before I found this posting. Great info.

I hope the actual Visual code qualityis better than the errorous sample here. It really can turn people off.

oldsb42  Monday, October 27, 2008 1:07 AM
Just started learning VC, your post was helpful.

Thank You
Shaheen
xCage  Tuesday, April 21, 2009 1:31 PM
This worked for me also. Thank's! Drumahh, I agree. This is also my first project and I hate it when they do that. To say nothing of the fact that you are prety much stuck with "MyProject" for the name of this one since they don't bother to tell you that the name can be anything you want it to be as long as you know what code to change. I took a chance and replaced the name where it seemed logical. I got lucky and only had to change it in two places. Okay, so I'm being petty but MyFirstMFCProject makes more sence to me. Every project that I create is going to be My Project. At least this way I have some idea of what it's all about. Thank's again guy's.

Tom
tweaton
Tweaton  Thursday, October 15, 2009 4:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Sandcastle does not preserve HTML white-space.
• Javascript calls displaying in topic abstracts
• Workflow as Method-wanabee
• چگونه Membershipها را برای پروژه خود سفارشی کنیم؟
• BuildAssembler encountered an error
• Technique to reduce the Documented file size!!
• Custom tags within Summary tags
• Help2 Compiler VS2008
• VS Team Foundation Server Documentation
• delete .net 1.0 and 1.1 after installation of 2.0?