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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wrighting to a database help

Status
Not open for further replies.

help120

Technical User
Apr 15, 2001
198
US
I'm having a problem writing to a database. I've one page called formroster.asp which takes all the information and a page called addroster.asp which adds the information to the database. Now my problem is with in the addroster.asp page. For some reason when I add info to the members database it also writes a line of empty code into recruits. You can view how it works here.. you can also view the code here and Any help would be much appreciated.
 
Instead of using the .addNew method of a recordset, why not try building up an INSERT statement, and then just executing that statement directly on your connection object?

Something like:
Code:
Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.ConnectionString = "DBQ=C:\inetpub\finalphase\databases\nps\roster.mdb;DRIVER={Microsoft Access Driver (*.mdb)}"
MyConn.Open 

dim sql

'build up first INSERT
sql = "INSERT INTO members (name,csdod,aim,icq,email) values("
sql = sql & "'" & strName & "',"
sql = sql & "'" & strcsdod & "',"
sql = sql & "'" & straim & "',"
sql = sql & "'" & stricq & "',"
sql = sql & "'" & stremail & "')"

'execute first statement
myConn.execute sql

'build up second statement
sql = "INSERT INTO recruit (name,csdod,aim,icq,email) values("
sql = sql & "'" & strName & "',"
sql = sql & "'" & strcsdod & "',"
sql = sql & "'" & straim & "',"
sql = sql & "'" & stricq & "',"
sql = sql & "'" & stremail & "')"

'execute second statement
myConn.execute sql

'clean up
set myConn = nothing

Notice that there's less to clean up now. This method is cleaner than adding with a recordset. Hopefully, it'll quit adding that trash for you, too.

:)
paul
penny.gif
penny.gif
 
Nope I'm still having the same problem. This is the code I used..

----------------------------------------------------------
<%
dim MyConn, sql, strName, strcsdod, straim, stricq, stremail, strNamer, strcsdodr, straimr, stricqr, stremailr

strName = Request.Form(&quot;txtName&quot;)
strcsdod = Request.Form(&quot;txtcsdod&quot;)
straim = Request.Form(&quot;txtaim&quot;)
stricq = Request.Form(&quot;txticq&quot;)
stremail = Request.Form(&quot;txtemail&quot;)

strNamer = Request.Form(&quot;txtNamer&quot;)
strcsdodr = Request.Form(&quot;txtcsdodr&quot;)
straimr = Request.Form(&quot;txtaimr&quot;)
stricqr = Request.Form(&quot;txticqr&quot;)
stremailr = Request.Form(&quot;txtemailr&quot;)

Set MyConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.ConnectionString = &quot;DBQ=C:\inetpub\finalphase\databases\nps\roster.mdb;DRIVER={Microsoft Access Driver (*.mdb)}&quot;
MyConn.Open



'build up first INSERT
sql = &quot;INSERT INTO members (name,csdod,aim,icq,email) values(&quot;
sql = sql & &quot;'&quot; & strName & &quot;',&quot;
sql = sql & &quot;'&quot; & strcsdod & &quot;',&quot;
sql = sql & &quot;'&quot; & straim & &quot;',&quot;
sql = sql & &quot;'&quot; & stricq & &quot;',&quot;
sql = sql & &quot;'&quot; & stremail & &quot;')&quot;

'execute first statement
myConn.execute sql

'build up second statement
sql = &quot;INSERT INTO recruit (name,csdod,aim,icq,email) values(&quot;
sql = sql & &quot;'&quot; & strNamer & &quot;',&quot;
sql = sql & &quot;'&quot; & strcsdodr & &quot;',&quot;
sql = sql & &quot;'&quot; & straimr & &quot;',&quot;
sql = sql & &quot;'&quot; & stricqr & &quot;',&quot;
sql = sql & &quot;'&quot; & stremailr & &quot;')&quot;

'execute second statement
myConn.execute sql

'clean up
set myConn = nothing
%>
 
You see their is 2 forms on formroster.asp one that will add to the members data base and the other will add to the recruits database. Now once they fill out the form it sends them to addroster.asp and from here it's opening up both the members and recruits databases and inserting information. What I need it to do is only open up the database from what was filled out on formroster.asp. As you can see this is how I’m sorting the information..

strName = Request.Form(&quot;txtName&quot;)
strcsdod = Request.Form(&quot;txtcsdod&quot;)
straim = Request.Form(&quot;txtaim&quot;)
stricq = Request.Form(&quot;txticq&quot;)
stremail = Request.Form(&quot;txtemail&quot;)

strNamer = Request.Form(&quot;txtNamer&quot;) <---------notice the r
strcsdodr = Request.Form(&quot;txtcsdodr&quot;)<---------notice the r
straimr = Request.Form(&quot;txtaimr&quot;)<---------notice the r
stricqr = Request.Form(&quot;txticqr&quot;)<---------notice the r
stremailr = Request.Form(&quot;txtemailr&quot;)<---------notice the r

r =recruit
 
AHA! I see what's going on now. Sorry for the hurried response before.

So what you need is some way to figure out what form they came from, and only execute the relevant statement. Easy enough.

What you need is a hidden form element on both pages. Call it 'origination' or something like that, and set it equal to the name of the form they are coming from. So for instance:

Member form:
<input type=hidden name=origination value=member>

Recruit form:
<input type=hidden name=origination value=recruit>

Then you need to check the value of that input to decide what you need to do. Try it like this:
Code:
<%
dim origination
origination = request.form(&quot;origination&quot;)

dim MyConn, sql, strName, strcsdod, straim, stricq, stremail, strNamer, strcsdodr, straimr, stricqr, stremailr

Set MyConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.ConnectionString = &quot;DBQ=C:\inetpub\finalphase\databases\nps\roster.mdb;DRIVER={Microsoft Access Driver (*.mdb)}&quot;
MyConn.Open 


if origination = &quot;member&quot; then

  strName = Request.Form(&quot;txtName&quot;)
  strcsdod = Request.Form(&quot;txtcsdod&quot;)
  straim = Request.Form(&quot;txtaim&quot;)
  stricq = Request.Form(&quot;txticq&quot;)
  stremail = Request.Form(&quot;txtemail&quot;)

  'build up INSERT
  sql = &quot;INSERT INTO members (name,csdod,aim,icq,email) values(&quot;
  sql = sql & &quot;'&quot; & strName & &quot;',&quot;
  sql = sql & &quot;'&quot; & strcsdod & &quot;',&quot;
  sql = sql & &quot;'&quot; & straim & &quot;',&quot;
  sql = sql & &quot;'&quot; & stricq & &quot;',&quot;
  sql = sql & &quot;'&quot; & stremail & &quot;')&quot;

  'execute member INSERT statement
  myConn.execute sql

elseif origination = &quot;recruit&quot; then

  strNamer = Request.Form(&quot;txtNamer&quot;)
  strcsdodr = Request.Form(&quot;txtcsdodr&quot;)
  straimr = Request.Form(&quot;txtaimr&quot;)
  stricqr = Request.Form(&quot;txticqr&quot;)
  stremailr = Request.Form(&quot;txtemailr&quot;)

  'build up recruit INSERT
  sql = &quot;INSERT INTO recruit (name,csdod,aim,icq,email) values(&quot;
  sql = sql & &quot;'&quot; & strNamer & &quot;',&quot;
  sql = sql & &quot;'&quot; & strcsdodr & &quot;',&quot;
  sql = sql & &quot;'&quot; & straimr & &quot;',&quot;
  sql = sql & &quot;'&quot; & stricqr & &quot;',&quot;
  sql = sql & &quot;'&quot; & stremailr & &quot;')&quot;

  'execute recruit INSERT statement
  myConn.execute sql

end if

'clean up
set myConn = nothing
%>

That oughta clear it up.

:)
paul
penny.gif
penny.gif
 
Thanks Paul for you help. I suspect I could have bypassed all this headache by only having one db and just adding in a table that collected ether &quot;member&quot; or &quot;recruit. Then when I went and called for the information I could have had the script sort it out. If you have time could you give me an ex? hehe thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top