Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert problem - auto increment is set

Status
Not open for further replies.

webIntern

Programmer
Nov 22, 2002
40
US
Hi all,

I have a web app that needs to insert into a table. This table has a field that is of numeric data type and it's set to auto-increment. It does not allow nulls. This field is called 'Ev_ID'. It is also the primary key. When I insert using query analyzer with the following sql statement (leaving it up to SQL Server to automatically insert into the Ev_ID field):
INSERT INTO Reg_Event(Ev_Name, Ev_Desc, Ev_Loc, Ev_MaxSlots, Ev_Presenter, Ev_Active) Values ('Testing', 'Testing', etc...etc...)

It works fine. But when I try to do it through the web app, I get the following error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'Ev_ID', table 'innovation.dbo.Reg_Event'; column does not allow nulls. INSERT fails.

The code for the SQL string is as follows:
if (Request.form("new_process") == "Y" ) {
strSql = " INSERT INTO Reg_Event(Ev_Name, Ev_Desc, Ev_Loc, Ev_MaxSlots, Ev_Presenter, Ev_Active)";
strSql+= " VALUES('"+strName+"','"+strDesc+"', '"+strLoc+"','"+numSlots+"', '"+strPres+"', '"+strAct+"') ";

again, leaving it up to SQL Server to insert into Ev_ID.

What could be the problem???!

 
Try using the profiler to see the sql that is being sent to the database.
Looks like for some reason what's being executed is not what you have there.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top