Advertisement

04.17.2008 at 07:29AM PDT, ID: 23330977
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How do I execute a parameterized stored query in MS Access using ole db consumer templates?

Asked by lcarr006 in Windows OLE Programming, Windows MFC Programming, Windows ATL / WTL / COM Programming

Tags: , ,

I am programming in c++ 9 (visual studio 2008) and using ole db consumer templates. I am able to call the stored queries, but I cant quite get the parameterized ones to work.

      Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
Here is the code:
 
	// Open DB
	CDataSource DataSource;
	CString m_DSN = "C:\\Program Files\\NYLBIS\\Database\\db1.MDB";
	CString m_connStr = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" + m_DSN + ";Mode=ReadWrite;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=4;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
	DataSource.OpenFromInitializationString(m_connStr.AllocSysString());
 
	// Create session object
	CSession Session;
	Session.Open(DataSource);
 
	CDBPropSet propset (DBPROPSET_ROWSET);
	propset.AddProperty(DBPROP_IRowsetChange, true);
	propset.AddProperty(DBACCESSOR_PARAMETERDATA, true);
	propset.AddProperty(DBACCESSOR_ROWDATA, true);	
      propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
 
	LPCSTR CommandText = "EXECUTE ZipcodeFilter ?";
 
	hr = m_command_mult.Create(Session, CommandText, DBGUID_DEFAULT); // hr = S_OK
	hr = m_command_mult.Prepare();	    // hr = S_OK
 
	// param vars
	const int ParamCount = 1;
	DBORDINAL dbOrd[ParamCount];
	DBPARAMBINDINFO dbBind[ParamCount];
 
	// set bind info
	// zipcode
        dbBind[0].bPrecision			= 0;
        dbBind[0].bScale			= 0;
        dbBind[0].dwFlags			= DBPARAMFLAGS_ISINPUT;
        dbBind[0].pwszName			= L"parm";
        dbBind[0].ulParamSize			= 5;
        dbBind[0].pwszDataSourceType	        = L"DBTYPE_WSTR";
        dbOrd[0] = 1;	// add parameter ordinal
 
	//Set the parameters information.	
	hr = m_command_mult.SetParameterInfo(ParamCount, dbOrd, dbBind); 
        // hr returns DB_E_BADTYPENAME
 
	// Bind the parameters with the accessor and command
	void* pDummy;
   hr = m_command_mult.BindParameters(&m_command_mult.m_hParameterAccessor, m_command_mult.m_spCommand,&pDummy);
// hr returns S_OK
 
	wchar_t* nParamValue1 = L"33173";
	flag = m_command_mult.SetParamString((ULONG)1, nParamValue1);   // flag returns false
 
	// Open the command.
        hr = m_command_mult.Open(); // hr returns "DB_E_ERRORSINCOMMAND"
 
 
 
ZipcodeFilter QueryString = 
SELECT Zipcode.*
FROM Zipcode
WHERE (((Zipcode.Zipcode)=[parm]));
[+][-]04.17.2008 at 11:04AM PDT, ID: 21379679

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 01:42PM PDT, ID: 21381166

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows OLE Programming, Windows MFC Programming, Windows ATL / WTL / COM Programming
Tags: Microsoft, Visual Studio, 2008
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.17.2008 at 01:52PM PDT, ID: 21381250

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_Related_20080208