While using the Fastinsert command its recives a error
1 view (last 30 days)
Show older comments
Hi friends...
I was tried to insert a record to MS SQL Database server using following commands.
NextECGID=5
tempPID=13;
ECG_RecordLink='C:\Documents\E5.jpg';
ECG_TakenDateTime=datestr(now, 'dd/mm/yy HH:MM:SS');
ECG_NResult='';
ECG_RecordCols = {'EcgRecordId','PatientID','TakenDateTime','NeuralDiagonosis','EcgRecordLink'};
ECG_RecordData = {NextECGID,tempPID,ECG_TakenDateTime,ECG_NResult,ECG_RecordLink};
con1 = database('SQLEXPRESS','','');
fastinsert(con1,'EcgRecord', ECG_RecordCols,ECG_RecordData);
close(con1);
But I received the following error.
??? Java exception occurred:
sun.jdbc.odbc.JdbcOdbcBatchUpdateException: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert explicit value for identity column in table
'EcgRecord' when IDENTITY_INSERT is set to OFF.
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(Unknown Source)
Error in ==> database.fastinsert at 212
StatementObject.executeBatch;
If you have any idea about this error please help me to resolve. Thanks!
Aruni F
0 Comments
Answers (1)
Walter Roberson
on 6 May 2011
Your ECG record ID is set to autoincrement -- that is, to automatically assign the next available value. In order to be able to provide your own values, you need to set the IDENTITY_INSERT property to ON .
(Unfortunately I do not know how to do that.)
2 Comments
Oleg Komarov
on 7 May 2011
You have:
1) to build a T-SQL command which sets the IDENTITY_INSERT to ON
2) or just skip that column when fastinserting
3) or modify the table properties in MS-SQL
Oleg Komarov
on 7 May 2011
Point 1)
exec(con1,'SET IDENTITY_INSERT EcgRecord ON')
fastinsert here
exec(con1,'SET IDENTITY_INSERT EcgRecord OFF')
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!