?
Solved

Set any parameter to NULL in OLE DB?

Posted on 2000-04-26
9
Medium Priority
?
299 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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