Simple Select

I am connecting to my db but I am unable to return results. I need to run a select statement and load a variable.

The database connection works great!

SQL Example I need: chrName = Select Name from Table where Userid = chrUserID;

chrUserID = This variable is loaded with logon id

///////////////////////////////////////////////////////////
char chrName[50]

_ConnectionPtr pConn = NULL;
_bstr_t strCon("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=qu;Password=q;Initial Catalog=PROD;Data Source=DHB123\\TOM");

HRESULT hr = S_OK;
CoInitialize(NULL);
try
{
//Create the Connection pointer
hr = pConn.CreateInstance((__uuidof(Connection)));
if(FAILED(hr))
{
goto cleanup;
}
//Open the SQL Server connection
hr = pConn->Open(strCon,"","",0);

if(FAILED(hr))
{
goto cleanup;
}

Every piece of code I have added here has failed. No select statement works correctly.

////////////////////////////////////////////////////
Last edited on
I don't see this post in the forum. Test
1
2
3
4
5
6
7
8
9
10
11
12
13
   _CommandPtr pCmd;
   hr = pCmd.CreateInstance(__uuidof(Command));
   if (FAILED(hr))    goto cleanup;

   pCmd->ActiveConnection = pConn;
   pCmd->CommandTimeout = 120;

   pCmd->CommandText = _bstr_t("select Name from Table where ....");
   _RecordsetPtr  pRec = pCmd->Execute(NULL, NULL, adCmdText);

   _bstr_t bsName = pRec->Fields->GetItem(_bstr_t("Name"))->Value;
   string strName = (char *)bsName;


Does this work?
Topic archived. No new replies allowed.