Solved

Set any parameter to NULL in OLE DB?

Posted on 2000-04-26
9
280 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
ID: 2753807
Adjusted points from 75 to 200
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 300 total points
ID: 2754038
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
ID: 2754062
Have a look at

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

"Status Values Used When Setting Data"
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:newstar
ID: 2754076
Adjusted points from 200 to 300
0
 

Author Comment

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

Expert Comment

by:NickRepin
ID: 2754231
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
ID: 2754248
Thanks,I think it must work.I'll try it.
0
 

Author Comment

by:newstar
ID: 2757981
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
ID: 2758006
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

809 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