Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: RE: Inserting nulls


Message #1 by "Vic" <vweston@m...> on Thu, 2 May 2002 16:57:35
thanks you...sure i will work it out...........eventually
Message #2 by shawnc@u... on Thu, 2 May 2002 05:00:04
> Shawn,

> Please explain how I can leave the field out of the insert statement 
> altogether?

Forgot one thing.

I usually explicitly set a field to NULL, but you could do something like:
-------------
Function InsertStatement(strTableName, strFormFields, strTableFields)
  strFormArray = split(strFormFields, ",")
  strTableArray = split(strTableFields, ",")
  strInsertFields = ""
  strValues = ""

  for x = lbound(strTableArray) to ubound(strTableArray)
    if len(request(strFormArray(x))) > 0 then
      strInsertFields = strInsertFields & "," & strTableArray(x)
      strValues = strValues & ",'" & replace(request(strFormArray
(x)), "'", "''") & "'"
    end if
  next

  InsertStatement = "INSERT INTO " & strTableName & " (" & mid
(strInsertFields,2) & ") VALUES (" & mid(strValues,2) & ")"   

End Function

sqlStatement = InsertStatement
("Customers", "lname,fname,address", "lastname,firstname,address")

conn.execute sqlStatement

------------

Message #3 by "Gavin Landon" <glandon@g...> on Thu, 2 May 2002 17:50:12 -0500
fname= request.form("fname")
if fname = "" then fname = vbNullString

"Drew, Ron" <RDrew@B...> wrote in message news:169289@a..._databases...

Not sure if I completely understand.  If you want to insert a space if
the form field is not entered.
Use IsNull function - syntax:
If IsNull(objField.Value) then
   Response.Write("&nbsp;")
End If

-----Original Message-----
From: Vic [mailto:vweston@m...]
Sent: Thursday, April 25, 2002 12:21 PM
To: ASP Databases
Subject: [asp_databases] Inserting nulls


On page one I have a form that collects inforamtion about a new user.
This
information is passed to page two like so:
<%
fname= request.form("fname")
sname= request.form("sname")
title1 = request.form("job")
title2 = request.form("titlenew")
dept_id = request.form("dept")
loc_id = request.form("loc")
extension= request.form("ext")
companymobile= request.form("mobile")
email= request.form("email")
photo= request.form("photo")

if title1 = "Select..." then
title = request.form("titlenew")
else
title = request.form("job")
end if

DIM objconn
set objconn = server.createobject("ADODB.Connection")
objconn.open = strcon
sqlrs = "Insert into people_listvic (fname, sname, loc_id, title,
dept_id,
extension, email, companymobile, photo) VALUES
('"&fname&"','"&sname&"','"&loc_id&"','"&title&"','"&dept_id&"','"&exten
sio
n&"','"&email&"','"&companymobile&"','"&photo&"')"
objconn.execute sqlrs
%>

Not all of the fields are required, so some of them are left blank on
page
one. These fields are inserted as blank fields and not <NULL>, which is
what I want as I use the NULL values in another page for displaying
information.

I am using MS SQLServer. Also, I'm not very experienced, so please
explain
as if you are talking to an idiot. Thanks very much.




Message #4 by shawnc@u... on Thu, 2 May 2002 04:56:55
> Shawn,

> Please explain how I can leave the field out of the insert statement 
> altogether?

I usually explicitly set a field to NULL, but you could do something like:
-------------
Function InsertStatement(strTableName, strFormFields, strTableFields)
  strFormArray = split(strFormFields, ",")
  strTableArray = split(strTableFields, ",")
  strInsertFields = ""
  strValues = ""

  for x = lbound(strTableArray) to ubound(strTableArray)
    if len(request(strFormArray(x))) > 0 then
      strInsertFields = strInsertFields & "," & strTableArray(x)
      strValues = strValues & ",'" & request(strFormArray(x)) & "'"
    end if
  next

  InsertStatement = "INSERT INTO " & strTableName & " (" & mid
(strInsertFields,2) & ") VALUES (" & mid(strValues,2) & ")"   

End Function

sqlStatement = InsertStatement
("Customers", "lname,fname,address", "lastname,firstname,address")

conn.execute sqlStatement

------------


  Return to Index