VC中如何执行SQL语句(用SQLServer的数据源)?

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:42:00
1、VC中想执行SQL语句用SQLServer的数据源,调用什么函数(包括详细的头文件)。就像DAO中执行Excute函数一样。
2、如何使用存储过程(有例子最好)。
回答得好(有相关例子),追加100分。感激不尽啊。
newghost_joe,程序很对,谢谢。要使用存储过程的代码怎么写?

使用 ADODB.Command 来调用存储过程,如:

Dim adoComm As Object
'// 创建一个对象,我们用来调用存储过程
Set adoComm = CreateObject("ADODB.Command")
With adoComm
'// 设置连接,假设 adoConn 为已经连接的 ADODB.Connection 对象
.ActiveConnection = adoConn
'// 类型为存储过程,adCmdStoredProc = 4
.CommandType = 4
'// 存储过程名称
.CommandText = "你的存储过程名称"
'// 设置输入参数
.Parameters.Item("@输入参数").Value = "值"
'// 执行存储过程
.Execute

If .Parameters.Item("@返回参数名称").Value = True Then

Else

End If
End With
'// 释放对象
Set adoComm = Nothing

用 CDatabase::ExecuteSQL();

CDatabase m_dbCust;
.....
CString strCmd = "UPDATE Taxes SET Federal = 36%";
try
{
m_dbCust.ExecuteSQL( strCmd );
}
catch(CDBException, e)
{
// The error code is