INSERT INTO SQL problem

I am doing:

pCommand->CommandText="INSERT INTO tblTest (Color, Texture) VALUES ('navy blue', 'rusty') ";
_RecordsetPtr pRecordset;

hr = pRecordset.CreateInstance (__uuidof (Recordset));

if (FAILED (hr))
{
AfxMessageBox ("Can't create an instance of Recordset");
return;
}
AfxMessageBox("LLL");

pRecordset->CursorLocation = adUseClient;
pRecordset->Open ((IDispatch *) pCommand, vtMissing, adOpenDynamic, adLockBatchOptimistic, adCmdTable);


I get an exception at the open statement....

Comments

  • What is the exeception msg?

    [size=2]Neo Gigs[/size]
    [color=blue]http://communities.msn.com.my/VisualBasicwithNeo[/color]

  • Well this could be the answer to your problem...
    //
    HRESULT hr;
    _CommandPtr pCommand = NULL;
    _RecordsetPtr pRecordset;

    pCommand.CreateInstance(__uuidof(Command));
    pCommand->ActiveConnection = pConn; // attach your connection object here
    pCommand->CommandTimeout = 15;
    pCommand->CommandType = adCmdText;
    pCommand->CommandText="INSERT INTO TableName VALUES (1,'test') ";


    hr = pRecordset.CreateInstance (__uuidof (Recordset));

    if (FAILED (hr))
    {
    AfxMessageBox ("Can't create an instance of Recordset");
    return;
    }

    AfxMessageBox("LLL");

    pRecordset->CursorLocation = adUseClient;
    pRecordset->Open ((IDispatch *) pCommand, vtMissing, adOpenDynamic, adLockBatchOptimistic, adCmdText);


    AfxMessageBox("Success");
    // end
    Enjoy...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories