While using the Fastinsert command its recives a error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2011년 5월 6일
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
Oleg Komarov
2011년 5월 7일
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
2011년 5월 7일
Point 1)
exec(con1,'SET IDENTITY_INSERT EcgRecord ON')
fastinsert here
exec(con1,'SET IDENTITY_INSERT EcgRecord OFF')
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!