| |

VerySource

 Forgot password?
 Register
Search
View: 849|Reply: 4

Error inserting data

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-14 22:30:02
| 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 ("Incorrect statement or condition input");
return;
}

pRst-> Close ();
pConn-> Close ();
pRst.Release ();
pConn.Release ();
CoUninitialize ();
I got an error when running:

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 the SQL query analyzer.After I executed, I deleted the records of '4564' and '654', and then executed it in vc, but it didn't work ...
Excuse me, why?
And this kind of error is only limited to the time of insertion and deletion, and there will be no mistake when querying.
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-12 12:00:01
| Show all posts
By the way, after prompting the error, go to the SQL to see the database.This data was successfully inserted, but the error prompt will appear during execution.
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-6-13 07:30:01
| Show all posts
If so?

CoInitialize(NULL);
{///Add a bracket here

_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
...
} ///Add a bracket here
CoUninitialize();
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-6 12:30:01
| Show all posts
Does bracketing have any practical meaning?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-26 13:45:01
| Show all posts
Rebuild all the program again!
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