I have a table employee where id is defined as auto increment
schema:
employee(id, name, company, salary, age)
insert into employee(name, company, salary, age)
values('John', 'ABC', 90000, 30);
This works. However, when doing the same thing via asp.net
SqlConnection xconn = new SqlConnection();
xconn.ConnectionString = @""; //connection details go here
xconn.Open()
String query = "insert into employee(name, company, salary, age) values(@name, @company, @salary, @age)";
SqlCommand ycmd = new SqlCommand(query, xconn);
ycmd.Parameters.Add("@name", name);
ycmd.Parameters.Add("@company", company);
ycmd.Parameters.Add("@salary", salary);
ycmd.Parameters.Add("@age", age);
ycmd.ExecuteNonQuery();
Here name, company, salary, age
contain the respective values.
I get an exception
Cannot insert value NULL into column ID, column does not allow nulls