Re: column cannot contain null values - autoincrement column
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Tue, 12 Dec 2006 22:54:07 +0000 (UTC)
David++ (David@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
I have a SQL Mobile database. I have defined in that database which has
once column which is set to auto increment when a new row is added. I
have a dataset which represents my database and have a table adapter
which links to that table. I have created a Sql query for the tabel
adapter which provides an Insert operation. By default the column set to
auto-increment was left out of the Insert statement which I think is th
correct behaviour. However, when I run this query from code it throws an
Exception - 'The column cannot contain null values. [Column name =
QAH_ID, Table name = QAHEADER]. I dont want to insert anything in that
column, I was hoping the column would auto increment by 1 on each
insert. Any ideas?
If SQL Server Mobile works like the real SQL Server, you should indeed
leave out that column. Maybe the columns is not IDENTITY after all?
Anyway, this should work:
DECLARE @id int
SELECT @id = coalesce(MAX(id), 0) + FROM tbl
INSERT tbl (id, ....
VALUES (@id, ....
(Again under the assumption that what works on SQL Server works on
SQL Server CE.)
Identity (or autonumber) values is quite an overvalued feature, and it
is often easier to roll your own.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- Prev by Date: RE: C++ connection to OleDbConnection
- Next by Date: meaning of table name in oledb consumer wizard
- Previous by thread: Re: Connect Table
- Next by thread: meaning of table name in oledb consumer wizard
- Index(es):
Relevant Pages
|
Loading