Problema String

Intrebari despre programarea cu VC++ incluzand mediul de dezvoltare, instalare, setari, debugger, compilator, linker si documentatie.
Post Reply
flapmind
Junior
Junior
Posts: 8
Joined: 25 Aug 2008, 17:14
Judet: Brăila

Problema String

Post by flapmind » 15 Feb 2009, 15:23

:whorship: salutare .

Code: Select all

_bstr_t strConnectionString =_T("Driver={Microsoft Access Driver (*.mdb)};"
								 "Dbq="+strDatabase+";Uid=;Pwd="+strPassword+";");
Error 1 error C2308: concatenating mismatched strings
unde gresesc ? :) care e sintaxa corecta ? MUltumesc :yes:



neagu_laurentiu
Membru++
Membru++
Posts: 919
Joined: 23 Jul 2007, 11:32

Re: Problema String

Post by neagu_laurentiu » 15 Feb 2009, 15:42

Pune un + dupa prima linie:
flapmind wrote:_bstr_t strConnectionString =_T("Driver={Microsoft Access Driver (*.mdb)};"+
"Dbq="+strDatabase+";Uid=;Pwd="+strPassword+";");
Dar am dubii la concatenarea cu strDatabase ori strPassword pentru ca nu stiu tipul lor !

Apoi ce-ti trebuie BSTR & COM cand tu de fapt vrei un amarat de ODBC ce merge cu orice char* !

flapmind
Junior
Junior
Posts: 8
Joined: 25 Aug 2008, 17:14
Judet: Brăila

Re: Problema String

Post by flapmind » 15 Feb 2009, 15:58

neagu_laurentiu wrote:Pune un + dupa prima linie:
flapmind wrote:_bstr_t strConnectionString =_T("Driver={Microsoft Access Driver (*.mdb)};"+
"Dbq="+strDatabase+";Uid=;Pwd="+strPassword+";");
Dar am dubii la concatenarea cu strDatabase ori strDatabase pentru ca nu stiu tipul lor !

Apoi ce-ti trebuie BSTR & COM cand tu de fapt vrei un amarat de ODBC ce merge cu orice char* !
Pai strDatabase si strDatabase sunt CStringuri
Nu merge cu plusul (+) dupa prima linie
Error 1 error C2110: '+' : cannot add two pointers
Last edited by flapmind on 15 Feb 2009, 16:19, edited 1 time in total.

neagu_laurentiu
Membru++
Membru++
Posts: 919
Joined: 23 Jul 2007, 11:32

Re: Problema String

Post by neagu_laurentiu » 15 Feb 2009, 16:19

Atunci adauga totul intr-o variablia...

User avatar
Silviu Ardelean
Senior
Senior
Posts: 1175
Joined: 12 Jul 2007, 09:22
Judet: Timiş
Location: Timisoara
Contact:

Re: Problema String

Post by Silviu Ardelean » 15 Feb 2009, 16:19

Daca vrei sa folosesti operatorul de concatenare (+) trebuie sa ai:

Code: Select all

CString strConnectionString =_T("Driver={Microsoft Access Driver (*.mdb)};");
            strConnectionString += _T("Dbq=");
            strConnectionString += strDatabase;
            strConnectionString += _T(";Uid=;Pwd=");
            strConnectionString += strPassword;
             strConnectionString += _T(";");
Altfel, poti formata stringul de conexiune.

Code: Select all

CString   strConnectionString;
strConnectionString.Format(_T("Driver={Microsoft Access Driver (*.mdb)}; Dbq=\"%s\";Uid=;Pwd=\"%s\";"), strDatabase, strPassword);
De asemenea, in loc de CString poti avea atat std::wstring cat si std::string. ;)

flapmind
Junior
Junior
Posts: 8
Joined: 25 Aug 2008, 17:14
Judet: Brăila

Re: Problema String

Post by flapmind » 15 Feb 2009, 16:30

Da,Dar apoi ... E'Connection15::Open' : cannot convert parameter 1 from 'CString' to '_bstr_t'
try
{
pConnection->Open(strConnectionString, _T(("")), (("")), adOpenUnspecified);
}

User avatar
Silviu Ardelean
Senior
Senior
Posts: 1175
Joined: 12 Jul 2007, 09:22
Judet: Timiş
Location: Timisoara
Contact:

Re: Problema String

Post by Silviu Ardelean » 15 Feb 2009, 16:45

Atunci foloseste CComBSTR in loc de CString. ;)

flapmind
Junior
Junior
Posts: 8
Joined: 25 Aug 2008, 17:14
Judet: Brăila

Re: Problema String

Post by flapmind » 15 Feb 2009, 18:57

Dupa lupte seculare asta

Code: Select all

_bstr_t strConnectionString =_T("Driver={Microsoft Access Driver (*.mdb)};\"Dbq=") + strDatabase + _T(";Uid=;Pwd=") + strPassword + _T(";"); 
imi rezolva problema.Programul in sfarsit se compileaza.Dar imi da fatalitate. 3 Message Boxuri
1.IDispacth error #3150
2.Operation Was Canceled
3.Databse Connection Error.
Nu imi da fatalitatile doar cand rulez programul din VS ci si in afara lui.

User avatar
Silviu Ardelean
Senior
Senior
Posts: 1175
Joined: 12 Jul 2007, 09:22
Judet: Timiş
Location: Timisoara
Contact:

Re: Problema String

Post by Silviu Ardelean » 15 Feb 2009, 20:18

Faptul ca ti s-a compliat programul nu inseamna ca e si rezolvata problema. Erorile acestea spun totul...

Observ ca vrei sa lucrezi cu ADO care e bazat pe tehnologia COM. Prima data ar trebuii sa inveti cum se utilizeaza obiectele COM (de ex. inainte de Open tre sa aplelezi adecvat CoInitialize(), CreateInstance(), etc).

Daca chiar vrei sa folosesti ADO in C++, iti recomand sa folosesti cu incredere o suita de clase gata scrise si testate: http://www.codeproject.com/KB/database/ ... lass1.aspx.
Succes! :)

Post Reply