🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #4129

Re: Sample : connect to database Access - what`s wrong this code?

#4129
From: Vassiliev V.V.
Date: Thu, 21 Mar 2002 16:38
197 lines
6688 bytes
���� ��������.

 AnsiString Path = ExtractFilePath(Application->ExeName) + "Data\\";
//��� AnsiString Path = GetCurrentDir() + "\\Data\\";

ADOConnection1->Connected = false;

 ADOConnection1->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"
  "Data Source=" + Path + "test.mdb";

 ADOConnection1->LoginPrompt = false;
 ADOConnection1->Connected = true;


������, ��� �� �����?
� C, ��� ���������� �������� ������ \\ ���������������� ��� \, �.�.

AnsiString Str = "a\\b\\c";

����� ����� Str ����� a\b\c

� ���������,
�������� �.�.
http://www.oledbdirect.com

"Slava Sh." <slava@space.com> �������/�������� � �������� ���������:
news:3c99c030_1@dnews...
> SOS ! ( . . .  _ _ _ . . .)
>
> Help !!!
>
>
> VARIANT1
> ~~~~~~~~~
>
> Working code:
> ===========
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> //
> //  ����������
> //
>      try
>      {
>        if(DM->ADOConnection->Connected == true)
>        {
>         DM->ADOConnection->Close();
>        }
>
>         DM->ADOConnection->ConnectionTimeout = 15;
>         DM->ADOConnection->LoginPrompt = false;
> //
>       ConnectionString =
>
>     "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data
> Source=C:\\WORK\\C_Project\\BCB5\\testADO\\Data\\cat22.mdb";
>
> //
>         DM->ADOConnection->ConnectionString = ConnectionString;
>
> //
>         DM->ADOConnection->Open("Admin", "");
> //
>         DM->CATADOTable->Connection = DM->ADOConnection;
>         DM->CATADOTable->Open();
>         DM->RISADOTable->Connection = DM->ADOConnection;
>         DM->RISADOTable->Open();
>         DM->DETADOTable->Connection = DM->ADOConnection;
>         DM->DETADOTable->Open();
>         DM->SEDADOTable->Connection = DM->ADOConnection;
>         DM->SEDADOTable->Open();
>         DM->UZLADOTable->Connection = DM->ADOConnection;
>         DM->UZLADOTable->Open();
>     }
>      catch(EOleException &E)
>      {
>       Application->MessageBox(
>       "��������� �������������� �������� ��� ���������� � ����� ������ !",
>       "����������� ������",
>       MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
>      }
> }
>
>
>
> VARIANT2:
> ~~~~~~~~~
>
> NOT WORKING CODE (ERROR -> "C:\WORK\C_Project\BCB5\testADO\Data\cat22.mdb'
> is not valid path)
>
============================================================================
> ====
> note: path exist !!!
>
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> //
> //  ����������
> //
>      try
>      {
>        if(DM->ADOConnection->Connected == true)
>        {
>         DM->ADOConnection->Close();
>        }
>
>         DM->ADOConnection->ConnectionTimeout = 15;
>         DM->ADOConnection->LoginPrompt = false;
> //
> // Get current Dir
> //
>         GetCurrentDirectory(MAX_PATH, CurPath);
>
>         PathToDatabase = ExtractFilePath(CurPath) + "\Data";
>         FileNameOfDatabase = "cat22.mdb";
>         PathToDatabase += "\\" + FileNameOfDatabase;
>
>         CurPath[0] = '\0';
>         strcpy(CurPath, PathToDatabase.c_str());
>
>         TempPath[0] = '\0';
>
>         int j = 0;
> //
> // add '\' + '\'
> //
>         for(int i = 0; i <= strlen(CurPath) - 1; i++)
>         {
>          TempPath[j] = CurPath[i];
>
>          if(TempPath[j] == '\\')
>          {
>           j++;
>           strcat(TempPath, "\\");
>          }
>          j++;
>         }
>
>         TempPath[j] = '\0';
> //
> // TempPath[] = >>>>
"C:\\WORK\\C_Project\\BCB5\\testADO\\Data\\cat22.mdb";
> //
>       ConnectionString=  "Provider=Microsoft.Jet.OLEDB.4.0;Persist
Security
> Info=False;Data Source=";
>       ConnectionString += AnsiString(TempPath);
> //
>         DM->ADOConnection->ConnectionString = ConnectionString;
> //
>         if(GetFileAttributes(TempPath) == 0xFFFFFFFF)
>         {
>           Application->MessageBox(
>         "File not exist !",
>         TempPath,
>         MB_OK+MB_SYSTEMMODAL);
>         }
>          else
>          {
>                 Application->MessageBox(
>         "OK - try to connect...",
>         TempPath,
>         MB_OK+MB_SYSTEMMODAL);
>
> //
> // try to connect  (file exist !!!)
> //
>         DM->ADOConnection->Open("Admin", "");
> //
>         DM->CATADOTable->Connection = DM->ADOConnection;
>         DM->CATADOTable->Open();
>         DM->RISADOTable->Connection = DM->ADOConnection;
>         DM->RISADOTable->Open();
>         DM->DETADOTable->Connection = DM->ADOConnection;
>         DM->DETADOTable->Open();
>         DM->SEDADOTable->Connection = DM->ADOConnection;
>         DM->SEDADOTable->Open();
>         DM->UZLADOTable->Connection = DM->ADOConnection;
>         DM->UZLADOTable->Open();
>     }
>      catch(EOleException &E)
>      {
>       Application->MessageBox(
>       "��������� �������������� �������� ��� ���������� � ����� ������ !",
>       "����������� ������",
>       MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
>      }
> }
>
> What`s wrong in VARIANT 2?
>
> Slava
>
>
Technical Details
Message-ID: <3c9a0cdc_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!207.217.77.43.MISMATCH!newsfeed1.earthlink.net!newsfeed.earthlink.net!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3c99c030_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: UKRAINIAN,KOI8R
X-Google-Thread: 10698b,cf9389e373692e47
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2002-03-21 08:47:42 PST
From: "Vassiliev V.V." <vv_vas@iname.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3c99c030_1@dnews>
Subject: Re: Sample : connect to database Access - what`s wrong this code?
Date: Thu, 21 Mar 2002 19:38:45 +0300
Lines: 201
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 62.118.138.44
Message-ID: <3c9a0cdc_2@dnews>
X-Trace: dnews 1016728796 62.118.138.44 (21 Mar 2002 08:39:56 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!207.217.77.43.MISMATCH!newsfeed1.earthlink.net!newsfeed.earthlink.net!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews