Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set any parameter to NULL in OLE DB?

Posted on 2000-04-26
9
Medium Priority
?
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:newstar
ID: 2753807
Adjusted points from 75 to 200
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 1200 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 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