| |

VerySource

 Forgot password?
 Register
Search
View: 992|Reply: 2

Insert problem, urgent

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-10-12 10:00:01
| Show all posts |Read mode
The statement is as follows:
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));

pConn->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MobileInfo";
pConn->Open("","","",adConnectUnspecified);

_variant_t RecordsAffected;
CString StrSQL=_T("insert into Place values('4564','654')");
try
{
pConn->Execute(_bstr_t(StrSQL),&RecordsAffected,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("Statement or condition input error");
return;
}

pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
An error occurred during operation:

Runtime Error!
Program:...Visual Studio\MyProjects\MobileInfo\Debug\MobileInfo.exe

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

But this sentence
insert into Place values('4564','654')
It can be executed normally in SQL Query Analyzer. After I executed it, I deleted the records of '4564' and '654', and then executed it in vc, it would not work...
May I ask why?
And this kind of error is only limited to insert and delete, there will be no mistakes in query

By the way, after the error is prompted, go to the SQL to view the database. The data is successfully inserted, but an error message will appear when it is executed.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-13 09:00:01
| Show all posts
try
{
pConn->Execute(_bstr_t(StrSQL),&RecordsAffected,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("Statement or condition input error");
return;
}
You used TRY CATCH
Reply

Use magic Report

0

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 United States

Post time: 2020-10-13 09:15:01
| Show all posts
pRst->Close(); There is a problem with this sentence, pRst does not have a select, it is strange that it will not die if it is closed.
Generally, if (pRst != NULL&&pRst->adstate == adStateOpen)
{pRst->Close; pRst = NULL);}
Direct close sometimes will die when there is no data. I have been fooled many times and the lesson is very profound.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list