And inserting a record?
recordset->Open("INSERT INTO mytable VALUES ('Hello')",
connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly, ADODB::adCmdText);
recordset->Open("INSERT INTO mytable VALUES ('Goodbye')",
connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly, ADODB::adCmdText);
Cake. In fact, I insert two records. I guess selecting records is easy too?
recordset->Open("SELECT * from mytable", connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly, ADODB::adLockReadOnly, ADODB::adCmdText);
while(!recordset->ADOEOF)
{
_variant_t var;
var = recordset->Fields->GetItem(L"value")->GetValue();
std::cout << static_cast<char *>(_bstr_t(var.bstrVal)) << std::endl;
recordset->MoveNext();
};
Actually selecting records is bit more difficult in C++, then in Visual
Basic.
The code to
get at the value is a nesting of pointers within pointers. This can be a little
complex, but
really it’s easier than the naysayers had told us.
Finally, we close the recordset and DROP the table.
recordset->Close();
recordset->Open("DROP TABLE mytable", connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,
ADODB::adCmdText);
That was too easy. Who said ADO in C++ was all that difficult.
Comments