Inserting values into Table columns
Posted on 2012-04-07
I created a tale in an Sql Server database using the following code.
Create table FirstTable
(ID int Primary key Identity(1,1),
FName varchar(30) null,
LName varChar(50) null,
Comments varchar(100) null Default 'To be filled later'
As you can see the code allows for the column "Comments" to be null. The column also uses a default data which should be inserted automatically if the user doesn't enter his own data.
My problem is this: When I enter data directly (manually) into the table and leave out Column "Comments" the default is entered automatically as expected.
But when I try to insert a new record using code and leave out the value for the "comments" column Sql Server generates an error telling me: "Column name or number of supplied values does not match table definition." Here is an example of how I tried to insert a new record:
insert into FirstTable