Solved

Set any parameter to NULL in OLE DB?

Posted on 2000-04-26
9
278 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
 

Author Comment

by:newstar
ID: 2754076
Adjusted points from 200 to 300
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Method 'OpenReport' of the object Docmd failed 7 29
TFS Branching 4 77
Visual Studio 2015 locks debug executable 9 144
What the difference between blend and Visual Studio 3 78
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

861 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

24 Experts available now in Live!

Get 1:1 Help Now