473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Can't insert records from asp page with request.form

I'm trying to insert records into an sql database coming from a page
using the request
..form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

....not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
myconn.Execute (StrSql)

Thanks in advance

Jan 5 '07 #1
5 3717
..Net Sports wrote:
I'm trying to insert records into an sql database coming from a page
using the request
.form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

...not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
Insert these lines here:

Response.Write strSql
Response.End
myconn.Execute (StrSql)

Thanks in advance
Run the page and look at the resulting sql statement in the browser window.
This is the statement being sent to the database to be executed. Does it
look like it will run as desired in QA? if you still can't figure out the
problem, show us the sql statement.

Further points to consider:
Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures:
http://groups.google.com/group/micro...9dc1701?hl=en&
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jan 5 '07 #2

".Net Sports" <ba********@cox.netwrote in message
news:11*********************@v33g2000cwv.googlegro ups.com...
I'm trying to insert records into an sql database coming from a page
using the request
.form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

...not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
myconn.Execute (StrSql)

Thanks in advance
A PK cannot be null, so something must assign it every time a row is
inserted. Often that something is the default for that PK column, such as
(NEWID( ) ) if the column type is uniqueidentifier, or the next identity
value if it is an identity column. These sorts of self-maintaining PK
fields tend to make for a workable design.

If the PK in your table has no default (apparently the case) then your
insert code must generate a value for that field, that does not exist in the
table yet. Guaranteeing atomicity for this from [inherently multi-user] ASP
code can be a daunting task, so your best bet is to resolve this value on
the db side, as noted above.
-Mark
Jan 5 '07 #3

Mark McGinty wrote:
".Net Sports" <ba********@cox.netwrote in message
news:11*********************@v33g2000cwv.googlegro ups.com...
I'm trying to insert records into an sql database coming from a page
using the request
.form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

...not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
myconn.Execute (StrSql)

Thanks in advance

A PK cannot be null, so something must assign it every time a row is
inserted. Often that something is the default for that PK column, such as
(NEWID( ) ) if the column type is uniqueidentifier, or the next identity
value if it is an identity column. These sorts of self-maintaining PK
fields tend to make for a workable design.

If the PK in your table has no default (apparently the case) then your
insert code must generate a value for that field, that does not exist in the
table yet. Guaranteeing atomicity for this from [inherently multi-user] ASP
code can be a daunting task, so your best bet is to resolve this value on
the db side, as noted above.
-Mark
thanks for your reply, I am trying to assign 'geid' a default value
while editing the DDL table parameters, but all the expressions I use
(+ 1, 'geid' + 1, 'geid') are not accepted.
?????

Jan 5 '07 #4

"Bubba" <ar*****@yahoo.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>
Mark McGinty wrote:
>".Net Sports" <ba********@cox.netwrote in message
news:11*********************@v33g2000cwv.googlegr oups.com...
I'm trying to insert records into an sql database coming from a page
using the request
.form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

...not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
myconn.Execute (StrSql)

Thanks in advance

A PK cannot be null, so something must assign it every time a row is
inserted. Often that something is the default for that PK column, such
as
(NEWID( ) ) if the column type is uniqueidentifier, or the next identity
value if it is an identity column. These sorts of self-maintaining PK
fields tend to make for a workable design.

If the PK in your table has no default (apparently the case) then your
insert code must generate a value for that field, that does not exist in
the
table yet. Guaranteeing atomicity for this from [inherently multi-user]
ASP
code can be a daunting task, so your best bet is to resolve this value on
the db side, as noted above.
-Mark

thanks for your reply, I am trying to assign 'geid' a default value
while editing the DDL table parameters, but all the expressions I use
(+ 1, 'geid' + 1, 'geid') are not accepted.
?????
You're trying to reference the value in the previous row, it doesn't work
that way. Is there a reason you can't make it an identity column?

-Mark


Jan 5 '07 #5
Thanks Mark, ( and Bob), yes , making it an identity column is what I
was overlooking.
Mark McGinty wrote:
"Bubba" <ar*****@yahoo.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...

Mark McGinty wrote:
".Net Sports" <ba********@cox.netwrote in message
news:11*********************@v33g2000cwv.googlegro ups.com...
I'm trying to insert records into an sql database coming from a page
using the request
.form method. The table "general" has a primary key 'geid .' I get the
following error:

Cannot insert the value NULL into column 'geid', table 'general';
column does not allow nulls. INSERT fails.

...not sure how to include the 'geid' field into the scheme.

strSql = "insert into general (firstname,surname,company) values ('"
strSql = StrSql & Request.Form("firstname") & "', '"
strSql = StrSql & Request.Form("surname") & "', '"
strSql = StrSql & Request.Form("company") & "')"
myconn.Execute (StrSql)

Thanks in advance

A PK cannot be null, so something must assign it every time a row is
inserted. Often that something is the default for that PK column, such
as
(NEWID( ) ) if the column type is uniqueidentifier, or the next identity
value if it is an identity column. These sorts of self-maintaining PK
fields tend to make for a workable design.

If the PK in your table has no default (apparently the case) then your
insert code must generate a value for that field, that does not exist in
the
table yet. Guaranteeing atomicity for this from [inherently multi-user]
ASP
code can be a daunting task, so your best bet is to resolve this value on
the db side, as noted above.
-Mark
thanks for your reply, I am trying to assign 'geid' a default value
while editing the DDL table parameters, but all the expressions I use
(+ 1, 'geid' + 1, 'geid') are not accepted.
?????

You're trying to reference the value in the previous row, it doesn't work
that way. Is there a reason you can't make it an identity column?

-Mark
Jan 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Adams | last post by:
Hi forum I have three text fields set up on a page that when submitted I want them to be inserted in to a table but in differnt records at once. the code below only seems to insert the last field...
0
by: Suler Abou | last post by:
Hi, I'm having a problem with an SQL statement, I have a statement that goes like this: "INSERT INTO table VALUES('TransID','CID',etc...);" it basically adds new data to a table. When the...
1
by: Miguel Dias Moura | last post by:
Hello, i created an ASP.net / VB web page with Dreamweaver MX 2004. In this page i have an Asp.Net Multipagewith 6 panels. I added a Dreamweaver Insert Server Behavior which inserts the form...
3
by: | last post by:
I'm picking up an 'IMPORTS' error for a simple database insert based on two input entry boxes in my form? It says an 'Imports' statement must preceede any declarations....... is this perahps the...
2
by: r_o | last post by:
hi i'm new to this issue i'm developping a web application with an access database in my application there's a loop that gets values of a form like: lastElt=request("numberOfItems") for...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
1
by: deepaks85 | last post by:
Dear Friends, Please help me out where I am doing mistake...I am trying to insert records into my MSSQL database...but it always take me into the "page cannot be displayed"....Here is the code.......
18
by: dbertanjoli | last post by:
I have problems writing data from my webform to two linked tables. I am quiet sure that my insert into syntax is not correct. Please take a look if you have a moment, if not I understand: <% ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.