C++builder 连接Access
哪位大侠有用C++builder连接Access的完成示例代码(用程序连接的) 能给我发一份吗 564354093@qq.com 谢谢
[解决办法]
bool __fastcall TfrmWebLogin::ConnectServer(void)
{
FConnectDB = false;
AnsiString UIDb ;
UIDb = "Main.mdb" ;
if (!FileExists(UIDb))
{
FConnectDB = false ;
return FConnectDB;
}
try
{
AdoCN->Connected=false;
AdoCN->ConnectionString =" Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+UIDb+";Persist Security Info=False";
AdoCN->LoginPrompt = false;
AdoCN->Connected = true;
FConnectDB = true ;
}
catch(...)
{
}
return FConnectDB;
}
[解决办法]
怎么发到茶馆里了。这里是喝茶用的。
[解决办法]
void __fastcall TDataMod::TelDataInit(void)
{
String connStr="",tempStr="";
int j=0;
TIniFile *ini;
try
{
ADOConn1->Close();
// connStr="Provider=SQLOLEDB.1;Password=xzsat;Persist Security Info=True;User ID=sa;Initial Catalog=daw;Data Source=XJQ-SAT";
ini=new TIniFile(".//SAS_Config.ini");
tempStr=ini->ReadString("dataBase","数据库类型","SQLSERVER");
ini->WriteString("dataBase","数据库类型",tempStr);
if(tempStr=="SQLSERVER") //连接SQL SERVER
{
connStr="Provider=SQLOLEDB.1;Persist Security Info=True;";
tempStr=ini->ReadString("dataBase","密码","xzsat");
ini->WriteString("dataBase","密码",tempStr);
connStr+="Password="+tempStr+";" ;
tempStr=ini->ReadString("dataBase","用户名","sa");
connStr+="User ID="+tempStr+";" ;
ini->WriteString("dataBase","用户名",tempStr);
tempStr=ini->ReadString("dataBase","数据库名称","daw");
connStr+="Initial Catalog="+tempStr+";" ;
ini->WriteString("dataBase","数据库名称",tempStr);
tempStr=ini->ReadString("dataBase","服务器名(IP)","XJQ-SAT");
connStr+="Data Source="+tempStr+" " ;
ini->WriteString("dataBase","服务器名(IP)",tempStr);
}
else //连接ACCESS
{
// Provider=Microsoft.Jet.OLEDB.4.0;Password=123;Data Source=E:\VehData.mdb;Persist Security Info=True
connStr="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;";
tempStr=ini->ReadString("dataBase","密码","");
ini->WriteString("dataBase","密码",tempStr);
connStr+="Password="+tempStr+";" ;
//tempStr=ini->ReadString("dataBase","用户名","Admin");
//connStr+="User ID="+tempStr+";" ;
//ini->WriteString("dataBase","用户名",tempStr);
tempStr=ini->ReadString("dataBase","数据库名称","E:\VehData.mdb");
connStr+="Data Source="+tempStr+";" ;
ini->WriteString("dataBase","数据库名称",tempStr);
}
delete ini;
ADOConn1->ConnectionString=connStr;
ADOConn1->Open();
if(ADOConn1->Connected)
{
//Memo1->Lines->Add("数据库连接成功……");
TStringList* List=new TStringList;
tempStr="UserTable";
ADOConn1->GetTableNames(List,false);
for(j=0;j<List->Count;j++)
{
if(tempStr==(List->Strings[j]))
break;
}
if(j>=List->Count)
AddUserTable();
UserTable->Close();
UserTable->TableName=tempStr;
UserTable->Open();
UserTable->Last();
tempStr= FormatDateTime("'Veh_'yyyymm",Date());
for(j=0;j<List->Count;j++)
{
if(tempStr==(List->Strings[j]))
break;
}
if(j>=List->Count)
AddDataTable();
InsertTable->Close();
DisplayTable->Close();
InsertTable->TableName=tempStr;
DisplayTable->TableName=tempStr;
//InsertTable->Open();
//InsertTable->Last();
delete List;
DelDataTable();
try
{
String SqlStr="Select Top 100 * from ";
SqlStr+=tempStr;
SqlStr+=" order by VEH_ID desc";
DataMod->InsertQuery->Close();
DataMod->InsertQuery->SQL->Clear();
DataMod->InsertQuery->SQL->Add(SqlStr);
DataMod->InsertQuery->ExecSQL();
DataMod->InsertQuery->Open();
}
catch(...)
{
}
}
}
catch(...)
{
// ShowMessage("远程数据库连接失败,\n请检查网络连接和服务器!");
}
}