#include "ReleaseFreeSeat.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <string.h>
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_variant_t vRecordsAffected;
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
_bstr_t Database;
_bstr_t User;
_bstr_t Password;
_bstr_t Type;
const char *section = "database";
const char *key1 = "Database";
const char *key2 = "User";
const char *key3 = "Password";
const char *key4 = "Type";
const char *defaultstring = "no";
const char *ini = "\\dokoweb.ini";
char *filename;
char buffer[255];
TCHAR szPath[100];
GetCurrentDirectory(100, szPath);
filename = szPath;
filename = strcat(filename,ini);
DWORD ii;
ii = GetPrivateProfileString(section,
key1,
defaultstring,
buffer,
255,
filename);
Database = buffer;
ii = GetPrivateProfileString(section,
key2,
defaultstring,
buffer,
255,
filename);
User = buffer;
ii = GetPrivateProfileString(section,
key3,
defaultstring,
buffer,
255,
filename);
Password = buffer;
ii = GetPrivateProfileString(section,
key4,
defaultstring,
buffer,
255,
filename);
Type = buffer;
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Data Source=" + Database,User,Password,adModeUnknown);
}
}
catch(_com_error e)///
{
return 0;
}
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pConnection->Execute("UPDATE nb_mem SET mem_seatpos = null WHERE mem_seatf = 1",&vRecordsAffected,adCmdText);
int threadcontroller = 0;
_bstr_t curpath;
section = "option";
const char *key = "freeaddress";
defaultstring = "no";
char aa[] = "YES";
GetPrivateProfileString(section,
key,
defaultstring,
buffer,
10,
filename);
CharUpper(buffer);
if (strcmp(buffer,aa) == 0)
{
// m_pConnection = m_pConnection;
// try
// {
m_pConnection->Execute("UPDATE nb_mem SET mem_seatpos = null WHERE mem_seatf = 1",&vRecordsAffected,adCmdText);
return 0;
// }
// catch(_com_error e)///
// {
// return 0;
// }
}
else
{
return 1;
}
}
#include "stdafx.h"
#include "ReleaseFreeSeat.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <string.h>
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_variant_t vRecordsAffected;
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
_bstr_t Database;
_bstr_t User;
_bstr_t Password;
_bstr_t Type;
const char *section = "database";
const char *key1 = "Database";
const char *key2 = "User";
const char *key3 = "Password";
const char *key4 = "Type";
const char *defaultstring = "no";
const char *ini = "\\dokoweb.ini";
char *filename;
char buffer[255];
TCHAR szPath[100];
GetCurrentDirectory(100, szPath);
filename = szPath;
filename = strcat(filename,ini);
DWORD ii;
ii = GetPrivateProfileString(section,
key1,
defaultstring,
buffer,
255,
filename);
Database = buffer;
ii = GetPrivateProfileString(section,
key2,
defaultstring,
buffer,
255,
filename);
User = buffer;
ii = GetPrivateProfileString(section,
key3,
defaultstring,
buffer,
255,
filename);
Password = buffer;
ii = GetPrivateProfileString(section,
key4,
defaultstring,
buffer,
255,
filename);
Type = buffer;
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Data Source=" + Database,User,Password,adModeUnknown);
}
}
catch(_com_error e)///
{
return 0;
}
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pConnection->Execute("UPDATE nb_mem SET mem_seatpos = null WHERE mem_seatf = 1",&vRecordsAffected,adCmdText);
int threadcontroller = 0;
_bstr_t curpath;
section = "option";
const char *key = "freeaddress";
defaultstring = "no";
char aa[] = "YES";
GetPrivateProfileString(section,
key,
defaultstring,
buffer,
10,
filename);
CharUpper(buffer);
if (strcmp(buffer,aa) == 0)
{
// m_pConnection = m_pConnection;
// try
// {
m_pConnection->Execute("UPDATE nb_mem SET mem_seatpos = null WHERE mem_seatf = 1",&vRecordsAffected,adCmdText);
return 0;
// }
// catch(_com_error e)///
// {
// return 0;
// }
}
else
{
return 1;
}
}
8 个解决方案
#1
HRESULT CoInitialize(NULL)先。
#2
在开头加入 :
#import "c:\\program files\\common files\\system\\ado\\msado10.dll" no_namespace rename("EOF","ADOEOF")
然后程序中加入:
CoInitialize();
#import "c:\\program files\\common files\\system\\ado\\msado10.dll" no_namespace rename("EOF","ADOEOF")
然后程序中加入:
CoInitialize();
#3
因为Connection、Recordset、Command等ADO对象以组件方式提供的,所以需要初始化COM库;
开始需要调用CoInitialize(NULL),最后需要调用CoUninitialize();
开始需要调用CoInitialize(NULL),最后需要调用CoUninitialize();
#4
谢谢你,不过我用的是一个WIN32 CONSOLE APPLICATION 的工程,没有CoInitialize()这个函数,而且msado10.dll也在StdAfx.h中倒入进来了。我可以发给你源程序,你能帮我调调么?真的很感谢!我的MSN是siyu9541@sohu.com,可以联系我,谢谢!
#5
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadocodeexamplesinvisualc.asp
随便找个例子看看就会.
随便找个例子看看就会.
#6
不会吧。先在cpp开头#inlude <objbase.h>
#7
问题解决了,谢谢大家!你们真的好厉害!!我出学VC,以后还要请大家多帮忙,
CoInitialize();这个都是从哪里知道的?呵呵,真牛!我的MSN在上面,希望结交更多的朋友.
CoInitialize();这个都是从哪里知道的?呵呵,真牛!我的MSN在上面,希望结交更多的朋友.
#8
从MSDN上知道的
#1
HRESULT CoInitialize(NULL)先。
#2
在开头加入 :
#import "c:\\program files\\common files\\system\\ado\\msado10.dll" no_namespace rename("EOF","ADOEOF")
然后程序中加入:
CoInitialize();
#import "c:\\program files\\common files\\system\\ado\\msado10.dll" no_namespace rename("EOF","ADOEOF")
然后程序中加入:
CoInitialize();
#3
因为Connection、Recordset、Command等ADO对象以组件方式提供的,所以需要初始化COM库;
开始需要调用CoInitialize(NULL),最后需要调用CoUninitialize();
开始需要调用CoInitialize(NULL),最后需要调用CoUninitialize();
#4
谢谢你,不过我用的是一个WIN32 CONSOLE APPLICATION 的工程,没有CoInitialize()这个函数,而且msado10.dll也在StdAfx.h中倒入进来了。我可以发给你源程序,你能帮我调调么?真的很感谢!我的MSN是siyu9541@sohu.com,可以联系我,谢谢!
#5
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadocodeexamplesinvisualc.asp
随便找个例子看看就会.
随便找个例子看看就会.
#6
不会吧。先在cpp开头#inlude <objbase.h>
#7
问题解决了,谢谢大家!你们真的好厉害!!我出学VC,以后还要请大家多帮忙,
CoInitialize();这个都是从哪里知道的?呵呵,真牛!我的MSN在上面,希望结交更多的朋友.
CoInitialize();这个都是从哪里知道的?呵呵,真牛!我的MSN在上面,希望结交更多的朋友.
#8
从MSDN上知道的