VC++操作SQLserver动态库【含源码】,及动态库使用教程。

VC++操作SQLserver动态库【含源码】

动态库使用Demo程序演示

#include <iostream>
#include <windows.h>
#include "sqlDataBase.h"
int main()
{
   
   
	if (SQLInit() == S_OK)
	{
   
   
		std::cout << "数据库连接成功" << std::endl;
	}
	return false;
}

使用SQLInit()函数连接数据库

【SqlDataBase】库头文件(.h)

/*

* "Copyright (c) 2021 by Sinux,Inc,liumeng"

*/

#ifndef __SQLDATABASE_H__
#define __SQLDATABASE_H__

#ifdef SQLDATABASE_EXPORTS
#define SQLDATABASEOPT_API __declspec(dllexport)
#else
#define SQLDATABASEOPT_API __declspec(dllimport)
#pragma comment(lib,"SqlDataBase.lib")
#endif

#include <string>

/**
*   SQL connect stringt
*	Provider=SQLOLEDB;Data Source=127.0.0.1,1433;Initial Catalog=sa;User Id=sa;Password=1
*	MS Access connect string
*	Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../../../data/db/Demo.mdb
*/
int     SQLDATABASEOPT_API   SQLInit(
    const std::string& strDataSource = "Provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=sa;User Id=sa;Password=123456",
    const std::string& strName = "",
    const std::string& strPwd = ""
);

void    SQLDATABASEOPT_API   SQLDestroy();
/*
*   查询数据
*   strSQL : SQL 语句
*   strResult:  结果 xml形式
*   返回值 > 0执行成功,返回记录的条数,否则失败
*/
int     SQLDATABASEOPT_API   SQLQuery(const std::string& strSQL, std::string& strResult);

/*
*   删除数据
*/
bool    SQLDATABASEOPT_API   SQLDelete(const std::string& value);
/*
*   添加数据,需要输入id
*/
bool    SQLDATABASEOPT_API   SQLInsert(const const std::string& str);
/*
*   更新数据
*/
bool    SQLDATABASEOPT_API   SQLUpdate(const std::string& str);

#endif

【SqlDataBase】库源代码(.cpp)

#define WIN32_LEAN_AND_MEAN 
#include <windows.h>
#include <mmsystem.h>
#include <atlbase.h>

#import "C:/Program Files/Common Files/System/ado/msado15.dll"  rename("EOF","EndOfFile")

#include "SqlDataBase.h"
#include <string>
#include <sstream>

using   std::string;
using   namespace ADODB;

/************************************************************************/
/*                         互斥体对象声明                               */
/************************************************************************/
class	Mutex
{
   
   
public:
	Mutex()
	{
   
   
		/**
		*   初始化临界区对象
		*	返回值>无
		*/
		::InitializeCriticalSection(&m_cs);
	}
	~Mutex()
	{
   
   
		/**
		*   释放临界区对象
		*   返回值>无
		*/
		::DeleteCriticalSection(&m_cs);
	}
	void	Lock()
	{
   
   
		/**
		*   进入临界截面
		*   返回值>无
		*/
		::EnterCriticalSection(&m_cs);
	}
	void	UnLock()
	{
   
   
		/**
		*   离开临界截面
		*   返回值>无
		*/
		::LeaveCriticalSection(&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值