菜鸟的一个小问题望老大们指教?

时间:2023-01-03 17:36:18
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cid=" + cCid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值


出现这样的错误:
1>e:\张华伟\vcgc\kuncunxinxiguanl\kuncunxinxiguanl\kuncunxinxiguanl\client.cpp(136): error C2678: 二进制“+”: 没有找到接受“const char [35]”类型的左操作数的运算符(或没有可接受的转换)
该怎么解决 谢谢了

7 个解决方案

#1


本帖最后由 VisualEleven 于 2012-01-10 05:48:12 编辑
#include "stdafx.h"
#include "kuncunxinxiguanl.h"
#include "Client.h"
#include "ADOConn.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#if !defined(AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_)
#define AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CClient::CClient()
{
Cid = 0;
Cname = "";
Ctype = 0;
Contact = "";
Address = "";
Postcode = "";
Phone = "";
Fax = "";
Memo = "";
}

CClient::~CClient()
{

}

int CClient::GetCid()
{
return Cid;
}

void CClient::SetCid(int iCid)
{
Cid = iCid;
}

CString CClient::GetCname()
{
return Cname;
}

void CClient::SetCname(CString cCname)
{
Cname = cCname;
}

int CClient::GetCtype()
{
return Ctype;
}

void CClient::SetCtype(int iCtype)
{
Ctype = iCtype;
}

CString CClient::GetContact()
{
return Contact;
}

void CClient::SetContact(CString cContact)
{
Contact = cContact;
}

CString CClient::GetAddress()
{
return Address;
}

void CClient::SetAddress(CString cAddress)
{
Address = cAddress;
}

CString CClient::GetPostcode()
{
return Postcode;
}

void CClient::SetPostcode(CString cPostcode)
{
Postcode = cPostcode;
}

CString CClient::GetPhone()
{
return Phone;
}

void CClient::SetPhone(CString cPhone)
{
Phone = cPhone;
}

CString CClient::GetFax()
{
return Fax;
}

void CClient::SetFax(CString cFax)
{
Fax = cFax;
}

CString CClient::GetMemo()
{
return Memo;
}

void CClient::SetMemo(CString cMemo)
{
Memo = cMemo;
}

//数据库操作
int CClient::HaveName(CString cCname)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cname='" + cCname + "'";//Sql.Format(_T("select * from caishiinfo where(菜名)values('%s')",Str));


//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "INSERT INTO Client (Cname, Ctype, Contact, Address, Postcode, Phone, Fax, Memo) VALUES('"
+ Cname + "'," + strType + ",'" + Contact + "','" + Address + "','" + Postcode + "','"
+ Phone + "','" + Fax + "','" + Memo + "')";

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_update(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "UPDATE Client SET Cname='" + Cname + "', Ctype=" + strType + ", Contact='" 
+ Contact + "', Address='" + Address + "', Postcode='" + Postcode + "', Phone='" 
+ Phone + "', Fax='" + Fax + "', Memo='" + Memo + "' WHERE Cid=" + cCid;

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_delete(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Client WHERE Cid=" + cCid;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

//根据客户编号读取所有字段值
void CClient::GetData(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cid=" + cCid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
CClient();
else
{
Cid = atoi(cCid);
Cname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Cname");
Ctype = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Ctype"));
Contact = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Contact");
Address = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Address");
Postcode = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Postcode");
Phone = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phone");
Fax = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Fax");
Memo = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Memo");
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

#endif 


这个文件就可以编译通过

#2


本帖最后由 VisualEleven 于 2012-01-10 05:48:57 编辑
#include "stdafx.h"
#include "kuncunxinxiguanl.h"
#include "Product.h"
#include "ADOConn.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#if !defined(AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_)
#define AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CProduct::CProduct()
{
Pid = 0;
Pname = "";
TypeId = 0;
Pstyle = "";
Punit = "";
Pprice = 0;
Plow = 0;
Phigh = 0;
Valid = 0;
AlarmDays = 0;
}

CProduct::~CProduct()
{

}

//设置和读取成员变量
int CProduct::GetPid()
{
return Pid;
}

void CProduct::SetPid(int iPid)
{
Pid = iPid;
}

CString CProduct::GetPname()
{
return Pname;
}

void CProduct::SetPname(CString cPname)
{
Pname = cPname;
}

int CProduct::GetTypeId()
{
return TypeId;
}

void CProduct::SetTypeId(int iTypeId)
{
TypeId = iTypeId;
}

CString CProduct::GetPstyle()
{
return Pstyle;
}

void CProduct::SetPstyle(CString cPstyle)
{
Pstyle = cPstyle;
}

CString CProduct::GetPunit()
{
return Punit;
}

void CProduct::SetPunit(CString cPunit)
{
Punit = cPunit;
}

float CProduct::GetPprice()
{
return Pprice;
}

void CProduct::SetPprice(float fPprice)
{
Pprice = fPprice;
}

int CProduct::GetPlow()
{
return Plow;
}

void CProduct::SetPlow(int iPlow)
{
Plow = iPlow;
}

int CProduct::GetPhigh()
{
return Phigh;
}

void CProduct::SetPhigh(int iPhigh)
{
Phigh = iPhigh;
}

int CProduct::GetValid()
{
return Valid;
}

void CProduct::SetValid(int iValid)
{
Valid = iValid;
}

int CProduct::GetAlarmDays()
{
return AlarmDays;
}

void CProduct::SetAlarmDays(int iAlarmDays)
{
AlarmDays = iAlarmDays;
}

//数据库操作
int CProduct::HaveName(CString cPname)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE Pname='" + cPname + "'";
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

int CProduct::HaveType(CString cTypeId)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE TypeId=" + cTypeId;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strTypeId;
strTypeId.Format("%d", TypeId);
CString strPrice;
strPrice.Format("%f", Pprice);
CString strPlow;
strPlow.Format("%d", Plow);
CString strPhigh;
strPhigh.Format("%d", Phigh);
CString strValid;
strValid.Format("%d", Valid);
CString strAlarm;
strAlarm.Format("%d", AlarmDays);

_bstr_t vSQL;
vSQL = "INSERT INTO Product (Pname, TypeId, Pstyle, Punit, Pprice, Plow, Phigh, Valid, AlarmDays) VALUES('" 
+ Pname + "'," + strTypeId + ",'" + Pstyle + "','" + Punit + "'," + strPrice + "," + strPlow + ","
+ strPhigh + "," + strValid + "," + strAlarm + ")";

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_update(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置UPDATE语句
CString strTypeId;
strTypeId.Format("%d", TypeId);
CString strPrice;
strPrice.Format("%f", Pprice);
CString strPlow;
strPlow.Format("%d", Plow);
CString strPhigh;
strPhigh.Format("%d", Phigh);
CString strValid;
strValid.Format("%d", Valid);
CString strAlarm;
strAlarm.Format("%d", AlarmDays);

_bstr_t vSQL;
vSQL = "UPDATE Product SET Pname='" + Pname + "', Pstyle='" 
+ Pstyle + "', Punit='" + Punit + "', Pprice=" 
+ strPrice + ", Plow=" + strPlow + ", Phigh=" + strPhigh
+ ", Valid=" + strValid + ", AlarmDays=" + strAlarm
+ " WHERE Pid=" + cPid;

//执行UPDATE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_delete(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Product WHERE Pid=" + cPid;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

//读取所有字段值
void CProduct::GetData(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE Pid=" + cPid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
CProduct();
else
{
Pid = atoi(cPid);
Pname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pname");
TypeId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TypeId"));
Pstyle = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pstyle");
Punit = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Punit");
Pprice = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pprice"));
Plow = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Plow"));
Phigh = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phigh"));
Valid = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Valid"));
AlarmDays = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("AlarmDays"));
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
#endif
这个就通过不了 就会报错
1>e:\张华伟\vcgc\kuncunxinxiguanl\kuncunxinxiguanl\kuncunxinxiguanl\product.cpp(154): error C2678: 二进制“+”: 没有找到接受“const char [36]”类型的左操作数的运算符(或没有可接受的转换)

#3


我已经搞定了 虽然不是很明白

#4


楼主自问自答。。厉害

#5


#include "Client.h"
我不明白的是为什么非得包含这个头文件就不报错了呢

#6



Some SQL Native Client APIs use connection strings to specify connection attributes. Connection strings are lists of keyword and associated values; each keyword identifies a particular connection attribute.

你上MSDN查吧,据说是连接数据库用的,不是太清楚!

#7


用CString::Format拼好字符串,然后转换为_bstr_t

#1


本帖最后由 VisualEleven 于 2012-01-10 05:48:12 编辑
#include "stdafx.h"
#include "kuncunxinxiguanl.h"
#include "Client.h"
#include "ADOConn.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#if !defined(AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_)
#define AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CClient::CClient()
{
Cid = 0;
Cname = "";
Ctype = 0;
Contact = "";
Address = "";
Postcode = "";
Phone = "";
Fax = "";
Memo = "";
}

CClient::~CClient()
{

}

int CClient::GetCid()
{
return Cid;
}

void CClient::SetCid(int iCid)
{
Cid = iCid;
}

CString CClient::GetCname()
{
return Cname;
}

void CClient::SetCname(CString cCname)
{
Cname = cCname;
}

int CClient::GetCtype()
{
return Ctype;
}

void CClient::SetCtype(int iCtype)
{
Ctype = iCtype;
}

CString CClient::GetContact()
{
return Contact;
}

void CClient::SetContact(CString cContact)
{
Contact = cContact;
}

CString CClient::GetAddress()
{
return Address;
}

void CClient::SetAddress(CString cAddress)
{
Address = cAddress;
}

CString CClient::GetPostcode()
{
return Postcode;
}

void CClient::SetPostcode(CString cPostcode)
{
Postcode = cPostcode;
}

CString CClient::GetPhone()
{
return Phone;
}

void CClient::SetPhone(CString cPhone)
{
Phone = cPhone;
}

CString CClient::GetFax()
{
return Fax;
}

void CClient::SetFax(CString cFax)
{
Fax = cFax;
}

CString CClient::GetMemo()
{
return Memo;
}

void CClient::SetMemo(CString cMemo)
{
Memo = cMemo;
}

//数据库操作
int CClient::HaveName(CString cCname)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cname='" + cCname + "'";//Sql.Format(_T("select * from caishiinfo where(菜名)values('%s')",Str));


//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "INSERT INTO Client (Cname, Ctype, Contact, Address, Postcode, Phone, Fax, Memo) VALUES('"
+ Cname + "'," + strType + ",'" + Contact + "','" + Address + "','" + Postcode + "','"
+ Phone + "','" + Fax + "','" + Memo + "')";

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_update(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "UPDATE Client SET Cname='" + Cname + "', Ctype=" + strType + ", Contact='" 
+ Contact + "', Address='" + Address + "', Postcode='" + Postcode + "', Phone='" 
+ Phone + "', Fax='" + Fax + "', Memo='" + Memo + "' WHERE Cid=" + cCid;

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CClient::sql_delete(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Client WHERE Cid=" + cCid;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

//根据客户编号读取所有字段值
void CClient::GetData(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cid=" + cCid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
CClient();
else
{
Cid = atoi(cCid);
Cname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Cname");
Ctype = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Ctype"));
Contact = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Contact");
Address = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Address");
Postcode = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Postcode");
Phone = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phone");
Fax = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Fax");
Memo = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Memo");
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

#endif 


这个文件就可以编译通过

#2


本帖最后由 VisualEleven 于 2012-01-10 05:48:57 编辑
#include "stdafx.h"
#include "kuncunxinxiguanl.h"
#include "Product.h"
#include "ADOConn.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#if !defined(AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_)
#define AFX_CLIENT_H__C210C883_216F_4A4E_BB2F_F034570AA92F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CProduct::CProduct()
{
Pid = 0;
Pname = "";
TypeId = 0;
Pstyle = "";
Punit = "";
Pprice = 0;
Plow = 0;
Phigh = 0;
Valid = 0;
AlarmDays = 0;
}

CProduct::~CProduct()
{

}

//设置和读取成员变量
int CProduct::GetPid()
{
return Pid;
}

void CProduct::SetPid(int iPid)
{
Pid = iPid;
}

CString CProduct::GetPname()
{
return Pname;
}

void CProduct::SetPname(CString cPname)
{
Pname = cPname;
}

int CProduct::GetTypeId()
{
return TypeId;
}

void CProduct::SetTypeId(int iTypeId)
{
TypeId = iTypeId;
}

CString CProduct::GetPstyle()
{
return Pstyle;
}

void CProduct::SetPstyle(CString cPstyle)
{
Pstyle = cPstyle;
}

CString CProduct::GetPunit()
{
return Punit;
}

void CProduct::SetPunit(CString cPunit)
{
Punit = cPunit;
}

float CProduct::GetPprice()
{
return Pprice;
}

void CProduct::SetPprice(float fPprice)
{
Pprice = fPprice;
}

int CProduct::GetPlow()
{
return Plow;
}

void CProduct::SetPlow(int iPlow)
{
Plow = iPlow;
}

int CProduct::GetPhigh()
{
return Phigh;
}

void CProduct::SetPhigh(int iPhigh)
{
Phigh = iPhigh;
}

int CProduct::GetValid()
{
return Valid;
}

void CProduct::SetValid(int iValid)
{
Valid = iValid;
}

int CProduct::GetAlarmDays()
{
return AlarmDays;
}

void CProduct::SetAlarmDays(int iAlarmDays)
{
AlarmDays = iAlarmDays;
}

//数据库操作
int CProduct::HaveName(CString cPname)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE Pname='" + cPname + "'";
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

int CProduct::HaveType(CString cTypeId)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE TypeId=" + cTypeId;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strTypeId;
strTypeId.Format("%d", TypeId);
CString strPrice;
strPrice.Format("%f", Pprice);
CString strPlow;
strPlow.Format("%d", Plow);
CString strPhigh;
strPhigh.Format("%d", Phigh);
CString strValid;
strValid.Format("%d", Valid);
CString strAlarm;
strAlarm.Format("%d", AlarmDays);

_bstr_t vSQL;
vSQL = "INSERT INTO Product (Pname, TypeId, Pstyle, Punit, Pprice, Plow, Phigh, Valid, AlarmDays) VALUES('" 
+ Pname + "'," + strTypeId + ",'" + Pstyle + "','" + Punit + "'," + strPrice + "," + strPlow + ","
+ strPhigh + "," + strValid + "," + strAlarm + ")";

//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_update(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置UPDATE语句
CString strTypeId;
strTypeId.Format("%d", TypeId);
CString strPrice;
strPrice.Format("%f", Pprice);
CString strPlow;
strPlow.Format("%d", Plow);
CString strPhigh;
strPhigh.Format("%d", Phigh);
CString strValid;
strValid.Format("%d", Valid);
CString strAlarm;
strAlarm.Format("%d", AlarmDays);

_bstr_t vSQL;
vSQL = "UPDATE Product SET Pname='" + Pname + "', Pstyle='" 
+ Pstyle + "', Punit='" + Punit + "', Pprice=" 
+ strPrice + ", Plow=" + strPlow + ", Phigh=" + strPhigh
+ ", Valid=" + strValid + ", AlarmDays=" + strAlarm
+ " WHERE Pid=" + cPid;

//执行UPDATE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

void CProduct::sql_delete(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Product WHERE Pid=" + cPid;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}

//读取所有字段值
void CProduct::GetData(CString cPid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Product WHERE Pid=" + cPid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

//返回各列的值
if (m_pRecordset->adoEOF)
CProduct();
else
{
Pid = atoi(cPid);
Pname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pname");
TypeId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TypeId"));
Pstyle = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pstyle");
Punit = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Punit");
Pprice = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pprice"));
Plow = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Plow"));
Phigh = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phigh"));
Valid = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Valid"));
AlarmDays = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("AlarmDays"));
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
#endif
这个就通过不了 就会报错
1>e:\张华伟\vcgc\kuncunxinxiguanl\kuncunxinxiguanl\kuncunxinxiguanl\product.cpp(154): error C2678: 二进制“+”: 没有找到接受“const char [36]”类型的左操作数的运算符(或没有可接受的转换)

#3


我已经搞定了 虽然不是很明白

#4


楼主自问自答。。厉害

#5


#include "Client.h"
我不明白的是为什么非得包含这个头文件就不报错了呢

#6



Some SQL Native Client APIs use connection strings to specify connection attributes. Connection strings are lists of keyword and associated values; each keyword identifies a particular connection attribute.

你上MSDN查吧,据说是连接数据库用的,不是太清楚!

#7


用CString::Format拼好字符串,然后转换为_bstr_t