ado
-
In my c++ code ..i use ADO commands..and to get the permissions..for userss for each and every databse.. i use the following commands.. sprintf(str1,"SELECT PERMISSIONS(OBJECT_ID('TABLE1'))"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); the abopve function returns an integer value.. how do i read the value?? ranjani
-
In my c++ code ..i use ADO commands..and to get the permissions..for userss for each and every databse.. i use the following commands.. sprintf(str1,"SELECT PERMISSIONS(OBJECT_ID('TABLE1'))"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); the abopve function returns an integer value.. how do i read the value?? ranjani
-
Use Recordset's Field property and use integer based index (0 in this case) to retrieve the value.
-
do u eman to say..use pRecordset->Fields()-> .. and what is integer basd index as u have mentioned??? plz reply as soon as poss thank u in advance ranjani
as far as I remember with ADO you would say:
_variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value
and this would retrieve the value.Item[]
can take either integer based index (eg.Item[long(0)]->Value
) or string based (eg.Item["SomeColumn"]->Value
) I hope this helps. Best regards, Husein -
as far as I remember with ADO you would say:
_variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value
and this would retrieve the value.Item[]
can take either integer based index (eg.Item[long(0)]->Value
) or string based (eg.Item["SomeColumn"]->Value
) I hope this helps. Best regards, HuseinThe full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani
-
as far as I remember with ADO you would say:
_variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value
and this would retrieve the value.Item[]
can take either integer based index (eg.Item[long(0)]->Value
) or string based (eg.Item["SomeColumn"]->Value
) I hope this helps. Best regards, HuseinThe full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani
-
The full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani
-
how do i create a stored procedure in C++? my program should for any of the sql servers.. so..manually creating a stored procedure won't work.. so.. i have to create it programatically...how do i go abt doing it? ranjani
-
Add a new _bstr_t variable and set it's value to "CREATE PROCEDURE ... " and then pass this variable as a parameter to connection's execute method. That could be one way of doing things. Best regards, Husein
-
Add a new _bstr_t variable and set it's value to "CREATE PROCEDURE ... " and then pass this variable as a parameter to connection's execute method. That could be one way of doing things. Best regards, Husein
iam able to create the stored procedure.. but how do i go about... rading the return value.. that is my code is now like.. _bstr_t bstrPr = "DROP PROCEDURE bali" ; pRecordset = m_pConnection->Execute(bstrPr, vRecordsAffected, 1); _bstr_t bstrp = "CREATE PROCEDURE bali @ioparm int OUTPUT AS \nIF PERMISSIONS()&2=0x2 RETURN 1 ELSE RETURN 0"; pRecordset = m_pConnection->Execute(bstrp, vRecordsAffected, 1); _bstr_t exect = "EXECUTE bali 2"; pRecordset = m_pConnection->Execute(exect,vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->GetFields()->Item[long(0)]->Value; printf("\n%d\n",(char *)(_bstr_t)vtMyVal); Iam not able tor ead the return value from this but.. what mite be the reason for this? what else shud i add to get it done?? also.. initially.. how do i cehk if a procedure name with the name specified already exists?? ranjani
-
iam able to create the stored procedure.. but how do i go about... rading the return value.. that is my code is now like.. _bstr_t bstrPr = "DROP PROCEDURE bali" ; pRecordset = m_pConnection->Execute(bstrPr, vRecordsAffected, 1); _bstr_t bstrp = "CREATE PROCEDURE bali @ioparm int OUTPUT AS \nIF PERMISSIONS()&2=0x2 RETURN 1 ELSE RETURN 0"; pRecordset = m_pConnection->Execute(bstrp, vRecordsAffected, 1); _bstr_t exect = "EXECUTE bali 2"; pRecordset = m_pConnection->Execute(exect,vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->GetFields()->Item[long(0)]->Value; printf("\n%d\n",(char *)(_bstr_t)vtMyVal); Iam not able tor ead the return value from this but.. what mite be the reason for this? what else shud i add to get it done?? also.. initially.. how do i cehk if a procedure name with the name specified already exists?? ranjani
ranjjj, how well do you know ADO programming with VC++? In order to get the RETURN_VALUE from the stored procedure, you need to execute it from the recordset and not from the connection. In you recordset object you need to set certain properties, like CommandType and CommandText. If you programmed ADO with VB, it is the same thing with VC++. regards, Husein