473,225 Members | 1,229 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,225 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 3711
..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
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.