在vc中,怎样掉sql server的存储过程?

fengge_76 2002-03-06 09:49:10
大体步骤,请谈以下。另外还有,接受返回来的记录集
...全文
59 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
strip 2002-03-10
  • 打赏
  • 举报
回复
那你害我白忙活,也不讲清楚!!!

你可以使用esqlc, 和流行的在vc中访问db2是一种方式,嵌入式

具体你自己去找吧,安装完sql server 之后在\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\esqlc下面,记得安装的时候选定安装源代码

我对你很客气了,下次少涮人,还嘴巴不饶人
fengge_76 2002-03-10
  • 打赏
  • 举报
回复
sorry,hehe,干吗这么生气?
我的没装上源代码,劳驾在贴一次,顺便烁烁怎么使
fengge_76 2002-03-09
  • 打赏
  • 举报
回复
这种方法我也会,据说在vc中可以直接掉,不用ado,应该怎么来写呢
strip 2002-03-08
  • 打赏
  • 举报
回复
msdn里面有一个sample:

ActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction Properties Example (VC++)
[This is preliminary documentation and subject to change.]
This example uses the ActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction properties to execute a stored procedure.

// BeginActiveConnectionCpp
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")

#define TESTHR(x) if FAILED(x) _com_issue_error(hr)

#include <stdio.h>
#include <ole2.h>
#include "conio.h"
#include "ActiveConnectionX.h"

//Function declaration
void ActiveConnectionX(VOID);
void PrintProviderError(_ConnectionPtr pConnection);

///////////////////////////////////////////////////////////
// //
// Main Function //
// //
///////////////////////////////////////////////////////////
void main()
{
if(FAILED(::CoInitialize(NULL)))
return;

ActiveConnectionX();

//Wait here for user to see the output..
printf("\n\nPress any key to continue..");
getch();

::CoUninitialize();
}



///////////////////////////////////////////////////////////
// //
// ActiveConnectionX Function //
// //
///////////////////////////////////////////////////////////
VOID ActiveConnectionX(VOID)
{
HRESULT hr = S_OK;

// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection = NULL;
_CommandPtr pCmdByRoyalty = NULL;
_RecordsetPtr pRstByRoyalty = NULL;
_RecordsetPtr pRstAuthors = NULL;
_ParameterPtr pPrmByRoyalty = NULL;


//Define Other variables
IADORecordBinding *picRs = NULL; //Interface Pointer declared.(VC++ Extensions) TCS(SPA)
CEmployeeRs emprs; //C++ class object TCS(SPA)
_bstr_t strAuthorId;
int intRoyalty;
VARIANT vtroyal ;

_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
"Initial Catalog=pubs;User Id=sa;Password=;");

try
{
//Define a command object for a stored procedure.

TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
hr = pConnection->Open(strCnn,"","",adConnectUnspecified);

TESTHR(pCmdByRoyalty.CreateInstance(__uuidof(Command)));

pCmdByRoyalty->ActiveConnection = pConnection;
pCmdByRoyalty->CommandText = "byRoyalty";
pCmdByRoyalty->CommandType = adCmdStoredProc;
pCmdByRoyalty->CommandTimeout = 15;

//Define stored procedure's input parameter.
printf("Enter Royalty : ");
scanf("%d",&intRoyalty);

//Assign Integer value
vtroyal.vt = VT_I2;
vtroyal.iVal = intRoyalty;

TESTHR(pPrmByRoyalty.CreateInstance(__uuidof(Parameter)));
pPrmByRoyalty->Type = adInteger;
pPrmByRoyalty->Size = 3;
pPrmByRoyalty->Direction = adParamInput;
pPrmByRoyalty->Value = vtroyal;
pCmdByRoyalty->Parameters->Append(pPrmByRoyalty);

//Create a recordset by executing a command.
pRstByRoyalty = pCmdByRoyalty->Execute(NULL,NULL,adCmdStoredProc);

//Open the authors table to get author names for display.

TESTHR(pRstAuthors.CreateInstance(__uuidof(Recordset)));
hr = pRstAuthors->Open("authors",strCnn,adOpenForwardOnly,adLockReadOnly,adCmdTable);

//Open an IADORecordBinding interface pointer which we'll use for Binding Recordset to a class
TESTHR(pRstAuthors->QueryInterface(__uuidof(IADORecordBinding),(LPVOID*)&picRs));

//Bind the Recordset to a C++ Class here
TESTHR(picRs->BindToRecordset(&emprs));


//Print current data in the recordset ,adding author names from author table.
printf("Authors With %d Percent Royalty",intRoyalty);

while(!(pRstByRoyalty->EndOfFile))
{
strAuthorId = pRstByRoyalty->Fields->Item["au_id"]->Value;
pRstAuthors->Filter = "au_id = '"+strAuthorId+"'";

printf("\n\t%s, %s %s",emprs.lau_idStatus == adFldOK ? emprs.m_szau_id : "<NULL>",\
emprs.lau_fnameStatus == adFldOK ? emprs.m_szau_fname : "<NULL>",\
emprs.lau_lnameStatus == adFldOK ? emprs.m_szau_lname : "<NULL>");

pRstByRoyalty->MoveNext();
}

// Clean up objects before exit
pRstByRoyalty->Close();
pRstAuthors->Close();

//Release the IADORecordset Interface here
if (picRs)
picRs->Release();
pConnection->Close();
}

catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

PrintProviderError(pConnection);
printf("Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
}

}



///////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
///////////////////////////////////////////////////////////

VOID PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
long nCount = 0;
long i = 0;

if( (pConnection->Errors->Count) > 0)
{
nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("Error number: %x\t%s", pErr->Number,(LPCSTR)pErr->Description);
}
}
}

// EndActiveConnectionCpp

ActiveConnectionX.h:

// BeginActiveConnectionH
#include "icrsint.h"


//This Class extracts fname,lastname

class CEmployeeRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CEmployeeRs)

//Column au_id is the 1st field in the recordset
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_szau_id,
sizeof(m_szau_id), lau_idStatus, TRUE)

ADO_VARIABLE_LENGTH_ENTRY2(2, adVarChar, m_szau_lname,
sizeof(m_szau_lname), lau_lnameStatus, TRUE)

ADO_VARIABLE_LENGTH_ENTRY2(3, adVarChar, m_szau_fname,
sizeof(m_szau_fname), lau_fnameStatus, TRUE)

END_ADO_BINDING()

public:

CHAR m_szau_id[20];
ULONG lau_idStatus;

CHAR m_szau_fname[40];
ULONG lau_fnameStatus;

CHAR m_szau_lname[40];
ULONG lau_lnameStatus;

};
// EndActiveConnectionH

See Also
ActiveConnection Property | CommandText Property | CommandTimeout Property | CommandType Property | Direction Property | Size Property

1,660

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧