Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE and DELETE is throwing error

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
US
hey,
have a question about CDatabase and CRecordset. I'm accessing MS SQLserver and my client has all privledges are set to Insert Delete and Update. I can view info from the database fine with the recordset but when i try and change the parameters and use an UPDATE or DELETE sql statement i get a "Runtime error
Program: <pathname>
abnormal program termination&quot;

//THIS CODE WORKS FINE
sSql = &quot;SELECT ALERT_ALARMID &quot;
&quot;FROM Alarm_Info &quot;
&quot;ORDER BY ALERT_ALARMID&quot;;

CDatabase DB;
DB.OpenEx(NULL,0);
CRecordset Record(&DB);
Record.Open(CRecordset::forwardOnly, sSql,
CRecordset::readOnly);
Record.GetFieldValue(&quot;ALERT_ALARMID&quot;, sItem1);
DB.CommitTrans();
DB.Close();

//THIS CODE THROWS THE ERROR
sSql = &quot;DELETE Alarm_Info &quot;
&quot;WHERE ALERT_ALARMID = 123&quot;;
CDatabase DB;
DB.OpenEx(NULL,0);
CRecordset Record(&DB);
Record.Open(CRecordset::dynaset, sSql,
CRecordset::none); //i've tried many variations

DB.CommitTrans();
DB.Close();

//i have read that Recordset allows only for reading however it it has all the params for updating and appending as well. Is there a better way of going about doing this?
I would just like to try and append or insert. This should be very easy. Also i am completely staying away from any of the class wizard stuff mainly because this particular file doesn't have the privledge of MFC. I just would like to manually update a record. Thanx for any feedback..sample code would be great!!
Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top