Solved

Set any parameter to NULL in OLE DB?

Posted on 2000-04-26
9
277 Views
Last Modified: 2013-12-03
I need to call a stored procedure in MS SQL Serer 7.0's database,How can I set any parameter in stored procedure to null.In ODBC, I know by CRecordset:SetParamNull all is ok,but in ole db.Thanks for any advice!!!

0
Comment
Question by:newstar
  • 5
  • 4
9 Comments
 

Author Comment

by:newstar
Comment Utility
Adjusted points from 75 to 200
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 300 total points
Comment Utility
It is relatively easy to set a parameter to null, but it's hard to call the stored proc. I don't know what you use - C++ or something else.

I've created my own classes to call OLE DB. Unfortunately, I cannot put them here - the C++ file is too long and complex.

In general, it looks like this.

1) Define your own parameters buffer.
For example,
struct {
  DBSTATUS statusParam;
  ULONG lengthParam;
  PVOID Param;
  // other parameters.
} buf;

Note that the statusParam is the important part.

2) Create accessor.

In DBBINDING structure, fill obValue, obStatus, obLength with the offsets of Param, statusParam, lengthParam (if required).

Set
dwPart=DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;

pIAccessor->CreateAccessor(...)

3) Call the command.

If the parameter is not NULL, then

buf.statusParam=DBSTATUS_S_OK;
buf.lengthParam=<param length>;
buf.Param=<param value>;
 
If the parameter is NULL, then

buf.statusParam=DBSTATUS_S_ISNULL;
buf.lengthParam=<not used>;
buf.Param=<not used>;

DBPARAMS dbparams;
....
dbparams.pData=&buf;
....
pICommand->Execute( .., &dbparams,... )


In the real life it's more complex, but there are examples in the part of the MSDN library related to the OLE DB.

In short, you have to use the DBBINDING.obStatus field and set the status field in the parameters buffer to DBSTATUS_S_ISNULL if you pass the NULL value and DBSTATUS_S_OK if you pass non-NULL value.

0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
Have a look at

http://msdn.microsoft.com/library/psdk/dasdk/olpr5q9f.htm

"Status Values Used When Setting Data"
0
 

Author Comment

by:newstar
Comment Utility
Adjusted points from 200 to 300
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:newstar
Comment Utility
Can we do fewer work by using a ole db template class:
 CCommand<TAccessor,TRowset,TMultiple>
Thanks!!!
0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
I have not used CCommand, because I have wrapped the native OLE DB interfaces into my own classes.

It seems that you have to use COLUMN_ENTRY_LENGTH_STATUS or any other appropriate COLUMN_xxx_STATUS macros to define an accessor.

Could you show your existing code to call the stored procedure?
0
 

Author Comment

by:newstar
Comment Utility
Thanks,I think it must work.I'll try it.
0
 

Author Comment

by:newstar
Comment Utility
Yes,It can work,too easy!For example:
   
1)the template class:T
DBSTATUS m_statusInParam;
TCHAR    m_InParam[10];

COLUMN_ENTRY_STATUS    (n,m_InParam,m_statusInParam)

2)use it:
T set;
set.m_statusInParam=DBSTATUS_S_ISNULL;
or
set.m_statusInParam=DBSTATUA_S_OK;
set.Open();
0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
That's what I said.
It's not a problem to set a parameter to NULL, it's much harder to understand the whole OLE DB.

OLE DB code is the biggest part of my current project. Its cpp file takes about 3,000 lines of code, inspite of that it's necessary to call only  ~15 stored procedures.

Thanks for points.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now