Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lkytmr
Starting Member
14 Posts |
Posted - 2002-12-05 : 11:27:01
|
| I am having a problem with an update statement that used to work and now is failing.Many things have changed since it last worked but I cannot understand why it is failing.The code is in Visual c++ 6.0 and is as follows: // 1. Test Connection if ( !m_bConnected || !t_pVehicle ) return FAILURE; char SQLquery[_MAX_SQL_STATEMENT] = "SELECT * FROM Vehicle where VehicleId = 0"; try { if( m_pRecordset->State == adStateOpen ) m_pRecordset->Close(); m_pRecordset->Open( SQLquery, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText ); m_pRecordset->AddNew(); m_pRecordset->Fields->Item["Source"]->Value = 3; m_pRecordset->Fields->Item["ModelID"]->Value = 2; m_pRecordset->Fields->Item["PaintLineID"]->Value = 5; m_pRecordset->Fields->Item["BaseColorID"]->Value = 1; m_pRecordset->Fields->Item["PrimeColorID"]->Value = 3; m_pRecordset->Fields->Item["ClearColorID"]->Value = 2; m_pRecordset->Fields->Item["VIN"]->Value = _variant_t( t_pVehicle->m_strVIN ); m_pRecordset->Fields->Item["TimeStamp"]->Value = 37595.429513889; //GetDateTimeStamp(); m_pRecordset->Fields->Item["VehicleOption"]->Value = 0; m_pRecordset->Update();The Update() fails with: - Error {DB_E_INTEGRITYVIOLATION} + __vfptr 0x0046441c const _com_error::`vftable' m_hresult 0x80040e2f - m_perrinfo 0x00f47be8 - IUnknown {...} + __vfptr 0x1f8bf778 - m_pszMsg 0x00000000 "" CXX0030: Error: expression cannot be evaluatedThe hresult is 0x80040e2f A specified value violated the integrity constraints for a column or table.SQL Profiler shows: exec sp_cursor 180150001, 4, 1, N'', @Source = 3, @VIN = '02339103947', @ModelID = 2, @BaseColorID = 1, @TimeStamp = 'Dec 5 2002 10:18AM', @PaintLineID = 5, @PrimeColorID = 3, @ClearColorID = 2, @VehicleOption = 0Trying this in enterprise manager as follows:INSERT INTO Vehicle (VehicleID, Source, VIN, ModelID, BaseColorID, [TimeStamp], PaintLineID, PrimeColorID, ClearColorID, VehicleOption)VALUES (0, 3, '02339102710', 2, 1, 37595.429513889, 5, 3, 2, 0)works ok:If it works in enterpise manager, why shouldn't it work with the update()?ThanksTom Ryan |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-12-05 : 11:47:03
|
| Is the TimeStamp column actually a datetime column, or is it another data type (even smalldatetime)? If you look at the Profiler trace you'll see that the @TimeStamp value was passed in a particular date format that might not be implicitly convertible. When you do the INSERT directly, you're using the decimal version that was used in the C++ code. If TimeStamp is NOT a datetime/smalldatetime column, then the C++ code is performing some kind of translation to a datetime format that it shouldn't be doing. |
 |
|
|
lkytmr
Starting Member
14 Posts |
Posted - 2002-12-05 : 15:33:14
|
| The column is a datetime column. I tried commenting out the // m_pRecordset->Fields->Item["TimeStamp"]->Value = 37595.429513889;statement and it had no effect.I tried commenting out all lines and just leaving the addnew() and update() and still no effect.It seems as if it just doesn't want to update the record, but why the odd error number? Seems that as often as not the error numbers just serve to confuse.Thankstom ryan |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-12-05 : 15:39:23
|
| The error message you posted has the words INTEGRITYVIOLATION in it. That would suggest to me that there is some sort of Foreign Key / Referential Integrity problem, such as trying to insert a new child record when the parent record doesn't exist. Take a look at your database schema to check this.------------------------------------------------------The more you know, the more you know you don't know. |
 |
|
|
|
|
|
|
|