It's me again! Maneging a datebase!

They have: 133 posts

Joined: Sep 2000

I have another ASP question Laughing out loud (I am startíng to believ, that I am the pesron, with the most topics in this forum)

I have found out how to write into a database, but I would like to be able to do more than that!

1: First of all, how do I just read the last entry in a database? I have an autonumber called "id" I want to retrieve the last "id", so that I can see from that how many entries, I have.

2: How do I instead of writing a new line each time I write to a database, just encrease the current (first) line with something, or overwrites it etc. I am trying to make a poll now, and first step for that, will be that...

There will be more things needed for me later on, eg. how to delete an entry in a databes, from the web, but I think that that will be very hard, and I doesn't need that one at the moment...

I will probably have more questions later, but I think that I am way ahead all you others, in making new threats in this forum Sticking out tongue so I wont need make more right noew Smiling Just kidding Roll eyes

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

1)
you can do this:

do while not rs.eof
rs.movenext
loop
'now your at then end
myVar = rs("myField")
'
or
'execute SQL query
rs.movelast
'now your at the end
myVar = rs("myField")
'
or
strSQL = "SELECT * FROM table ORDER BY Id DESC"
'Now, the first line is actually the line last entered
myVar = rs("myField")
'

so as you can see, there IS more than one way to skin a cat!

Mark Hensler
If there is no answer on Google, then there is no question.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

2)
first you will need to query the DB and get the number
then you will increment it
then you will shove it back into the DB

here we go...

'Let's get the count for the poll
stmSQL = "SELECT * FROM table WHERE Id=" & TheIdNumber
'execute SQL query
Count = rs("myPollCount")

'Now we need to increment the count
Count = Count + 1

'Now we need to put it back into the DB
stmSQL = "UPDATE table SET myPollCount='" & Count &"' WHERE Id=" & TheIdNumber
'execute SQL query
'

'UPDATE' will replace the fields you specify. If that row has more fields than you said in the query, they will not be changed (theyll keep the value they have). It's important to use the 'WHERE Id=' I don't know what will happen if you forget that, it might change all the rows...

Good Luck,
-Mark "Max Albert"

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Thanks!

I will look at it, and see what I can make!!

They have: 133 posts

Joined: Sep 2000

question 1 has been ansvered, and now works fine! But in the second question, I still have a problem...

You want me to write an Idnumber, but what number should that be? You show it as a variable, but how can I get a variable from the database, when I havent set the database first?

I have been able to encrease the number and so on, but now I only need to write it to the databse again...

The database is called poll.mdb
the table is called poll1

How do I write that?

Simple math

A new question: First of all I would like to know, how I plus "+" 3 variables, so that I get an integer!
Sofar I have been doing that by sayein var1=var2+var3 That does not give me the sum of the numbers!

Second of all, How do I round a number up? When I in my poll get the percantage (thats why I want the sum) it often gives me a number like 33,3333333333333333333 and that doesnt look very good, when I print it out on the screen!

If you can ansver those 3 questions, I will be dont with the poll!!!

Not as hard as I expeckted, though there are some lagging in my knowledge (a lot)

[thankfull]I thank you again for your other ansvers![/thankfull]

[Edited by hotcut on 10-14-2000 at 04:49 AM]

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Database looks like this:

+----+----------+-------+
| ID | PollName | Count |
+----+----------+-------+
| 1  | poll1    | 123   |
| 2  | poll2    | 456   |
+----+----------+-------+
'
Code like this:
'Let's get the count for the poll
stmSQL = "SELECT * FROM table WHERE PollName=" & PollToIncrement
'execute SQL query
Count = rs("Count")

'Now we need to increment the count
Count = Count + 1

'Now we need to put it back into the DB
stmSQL = "UPDATE table SET Count='" & Count &"' WHERE PollName=" & PollToIncrement
'execute SQL query
'

(You'd have to set the number in the DB manually... It's just there to have a unique field for each row in the table.)

This code is good if you have multiple polls/counters in one DB and table. If you only have one poll/counter in the table, then just say 'Id=1'.
If you do have mulitple 'thing' per table, then you an use the Id or PollName to specify which row to edit. Get it?

Rounding...

percent = round(percent*100)/100
'
This will round to two decimals.... First you multiply by 100. Then round it off to nearest whole number. Then devide by 100 to put the decimal back where it started Smiling.

Adding...

'this will give "var1" the value of var1,var2,var3 added together
var1 = var1 + var2 + var3

'this will give "total" the value
total = var1 + var2 + var3
'

Your Welcome!

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

I am starting to feell that we misunderstand each other very much!!! The round thing, works just fine, thanks for that, but I still dont understand the sav code!

I will try to explain how I have builded the table!

I have 1 table called "pool1"
inside that table, I have 3 rows!
1 named "spq1"
1 named "spq2"
1 named "spq3"

+----------+-------+
| spq1     | 10    |
| spq2     |  5    |
| spq3     |  5    |
+----------+-------+
'

That is how it is builded, now I dont understand why you have some kimd of "id" to that! Why cant I just say something like strSQL = "UPDATE poll1 SET spq='" & Count

Can you please somehow try to explain it... again...

adding...

Have found out how to now;I just had to say"*1" behind the numbers, and they could be added!

I hope that you can help me agian...

Casper

[Edited by hotcut on 10-15-2000 at 05:47 AM]

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

You need to think of it as a coordinate system...
watch:

+----+----------+-------+
| ID | PollName | <strong>Count</strong> |
+----+----------+-------+
| <strong>1</strong>  | poll1    | <strong><del>123</del></strong>   |
| 2  | poll2    | 456   |
+----+----------+-------+
'

The field (collumn) that you want to change is Count.
The record (row) that you want to change is the first one... which can be identified by 'Id=1' or 'PollName=poll1' (it doesn't matter, as long as their are no duplicates)

As far as:
strSQL = "UPDATE poll1 SET spq='" & Count
This is the wrong syntax. I don't know what this will do. It may give set 'spq' equal to 'Count' on all rows (this is not desired Smiling) So you need to give it some other info to find the right row...
strSQL = "UPDATE poll1 SET fieldname='" & Count &"' WHERE row='" & rownumber & "'"

In your table...
'fieldname' is the name of the field that holds the numbers.
'row' is the name of the field that holds "spq1", "spq2", and "spq3".

Make sense? It's like a coordinate system with a X and Y axis. You'll use both to identify the cell that you want to edit.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

I think that we are still misunderstanding each other... First of all, my database is made in design mode, becourse that is the only way, that I know how to... I am not sure if you know that it is made like that...

Then I amj not sure, if you know what I actually mean by a poll, What I mean is that you first ansver a question, with e.g. 3 ansvers, then my script will save the ansver, and make a ?diagram? (with 3 bars) so that you can see, how many percentages of the people that think what.

Now I will show you how my database is build, remember it is in design mode! The bold poll, is the one we are talking about now. What you see below, is how it looks, when I start access, and see the different tables; This is only the tables below)

+----------+
| <strong>poll1</strong>    |
| poll2    |
+----------+
'

So far, so good. I think that you understand that part now. All I am correcting now is the bold part; poll1

Inside the table, called poll1, I have three fields. They are made in design mode... I will show you that now: ohh, yea and by the way, the name, and the value is not written in the database, just to explain you what there is below...

+----------+-------+
| (name)   |(value)|
+----------+-------+
| spq1     | 123   |
| spq2     | 456   |
| spq3     | 2     |
+----------+-------+
'

This means, that 123 people have ansvered ansver 1, 456 people ansver 2 and 2 ansver 3

Do you see?

I hope that you follow me this far. I will now first give you the code, to the page, where the user enters his ansver. The code is below:

<html>
<head>
<title>Vote!</title>
</head>

<body><br><br><br><br><br><br>



<font face="cursive" color="Red">


<H2>Do you eat dogs??</h2><br></font>
<form method="POST" action="pollproc.asp" name="poll">

<table>
<tr>
<td>Daily!</td>
<td><input type="radio" name="spq" value="spq1"><br></td>
</tr>
<tr>
<td>At Christmas only!</td>
<td><input type="radio" name="spq" value="spq2"><br></td>
</tr>
<tr>
<td>Yea, right, NEVER!!!</td>
<td><input type="radio" name="spq" value="spq3"><br></td>
</tr>
</table>

<input type="submit" value="Vote!">
</form>
</body>
</html>
'

This is a very simple page, it asks you if you eat dogs (hypothetical, ofcourse), then you can choose to ansver:

Daily

At Christmas, only

Yea right, NEVER!!!

Depending on what you ansver, the ansver will be either spq1/2/3

The ansver that you choose, is the field in the databse, that needs to be changed.

I will now show you the code, that I am using to write it all out, on the screen. The bold part is the part, where I am saving, and so on...

<% Option Explicit %>

<html>
<head>
<title>Resultatet...</title>
</head>

<body>
<%
dim streng1, streng2, sti, AccessDataBase, strSQL, dbconnection, rsRecordSet, sRecordSet

sti = "c:\asp"
Streng1 = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ="
Streng2 = "\poll.mdb;UID=admin;PWD=;"
AccessDataBase = Streng1 & sti & Streng2

strSQL = "SELECT * FROM poll1"
Set dbConnection = Server.CreateObject("ADODB.Connection")
Set rsRecordSet = Server.CreateObject("ADODB.RecordSet")
dbConnection.Open AccessDataBase
rsRecordSet.Open strSQL, dbConnection, 2, 3



<strong>

dim spq, count, formervalue
spq = Request.Form("spq")
formervalue = rsRecordSet(spq)
count = formervalue + 1

strSQL = "UPDATE poll1 SET fieldname='" & Count &"' WHERE row='" & spq & "'"
</strong>

dim spq1, spq2, spq3, spq1width, spq2width, spq3width, total

spq1 = rsRecordSet("spq1")*1
spq2 = rsRecordSet("spq2")*1
spq3 = rsRecordSet("spq3")*1
total = spq1+spq2+spq3
spq1width = (spq1/total)*100
spq2width = (spq2/total)*100
spq3width = (spq3/total)*100
Response.Write total
spq1width = round(spq1width*10)/10
spq2width = round(spq2width*10)/10
spq3width = round(spq3width*10)/10



Response.Write "<br><br><br><br><br><br>"
'writing out the result

Response.write("<table cellpadding='10'>")


Response.write("<tr> <td>Du må ikke begå drab!</td><td><img src='poll.gif' height='15' width='" & spq1width & "'> " & spq1width & " %<br></td></tr>")

Response.Write("<tr><td>Dræb kun hvis du har et ordentligt alibi!</td> <td><img src='poll.gif' height='15' width='" & spq2width & "'> " & spq2width & " %<br></td></tr>")

Response.Write("<tr> <td>Dræb løs, vi skal alligevel alle dø en dag!</td> <td><img src='poll.gif' height='15' width='" & spq3width & "'> " & spq3width & " %<br></td></tr>")


Response.write("</table>")


dbConnection.Close
Set rsRecordSet = Nothing
Set dbConnection = Nothing
%>


</body>
</html>
'

That is what I am using for it. The last bold line, is the one, that we are working on. If you can write me, what EXACTLY there has to be written there, we will be done...

Thanks for your many ansvers, and I hope that we can get this one solved soon

Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I know what you want to do. I just finished writing a complex polling script [alpha version, undergoing beta testing]. I wrote it in PHP3/mySQL.

I'm a bit confused as to how your DB is set up. I've never seen a DB that looked sideways. Can you email me the DB file? [if you can find me email addr. let me know]

What version Access are you using? I just opened my version [Access 2000] and made a fake DB and it looked like this:

+---+------+------+------+
|   | spq1 | spq2 | spq3 |
+---+------+------+------+
|___|_123__|_456__|_789__|
| > |      |      |      |
+---+------+------+------+
'

Are you looking at it in 'datasheet view' after you build it in 'design view'?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Hi Max

I have now mailed the database to you, but I donnot think that you will need it anymore!

The problem was that we were looking at the database in 2 different ways, so that it didnt seem right!

As you have just said your self, the databe soes look like this:

+---+------+------+------+
|   | spq1 | spq2 | spq3 |
+---+------+------+------+
|___|_123__|_456__|_789__|
'

So that is good.

I will now, with the new knowledge I have gotten, from understandnig you, try again, to see if I can make it work... I will post a message imidiatly if I find the ansver, though I am affreid that I still cant. I have no "id" field, but I will try using "1" as the "id".

If I dont post a message, when you see this post, it means that I havent found a solution.

Casper


UPDATE:

As I said, I have tryed to make it work, but AGAIN I failed Sad

I hope that you will... AGAIN try to help me out... I will aprechiate it very much, if you can...

[Edited by hotcut on 10-17-2000 at 10:58 AM]

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

OK ...this is looking better.

This should now have a quite simple solution... View the table in 'Design' mode and just add an 'Id' field. It doens't have to be auto_increment because you'll only be using one row.

so now, your table should look like this:

+---+------+------+------+----+
|   | spq1 | spq2 | spq3 | id |
+---+------+------+------+----+
|___|_123__|_456__|_789__|_1__|
'

Then your bold code should be this:

dim spq, count, formervalue
spq = Request.Form("spq")
formervalue = rsRecordSet(spq)
count = formervalue + 1

strSQL = "UPDATE poll1 SET " & spq "='" & Count &"' WHERE row='1'"

'Don't forget to execute the query!
'

Let me know if this doesn't work... [again, hehe]

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

What the *biip*?

I actually did write a repley to this post yesterday, but unfortunetly the forum dopesnt seem to have gotten it... I was hoping to get home to a sollution today...

Ok, I will try to say, what I tryed yesterday...

What can I say? It didnt work!

I get no error messages at all, no sign of any trouble, nothing!

You wrote, last time: 'Don't forget to execute the query!
What query were you talking about? I suppose that it was the one, that opens up the connection, for the databse, but how do I execute it? Wont it happen, if I just write it?

We can see the goal, but we can reach it... Hope you got what it take to bring me up to speed.

Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Here are the last two line of your first query:

dbConnection.Open AccessDataBase
rsRecordSet.Open strSQL, dbConnection, 2, 3
'
The first line opens the connection to the DB.
The second line executes the query.

because you don't close the connection later, we can use it again. So all you have to do is copy the last line to the end of your second query.

Ideally, you would say:
set rsConnection = Nothing
set rsRecordSet = Nothing
This just cleans things up. But this isn't neccessary, because they'll be erased when the script is done executing. If you don't understand this last paragraph, ignore it, you don't need it.

Mark Hensler
If there is no answer on Google, then there is no question.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Max,

While the connection and recordset will eventually timeout they will not be erased when the script has finished executing. Until the database server receives a close response from the client it will assume you are still using the recordset. This could be deadly with a busy site. So for this example you would:

rsRecordSet.Close
Set rsRecordSet = nothing
rsConnection.Close
Set rsConnection = nothing

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Thanks for your repley(s) again.

Eealyer in this thread, I have written all my code out to you, where it allso said, that I actually executed those strings!

Now I hope, that there are 2 people able to help me now, so I will write you the code, that I think is the importgant part.

I am getting all the info. right from the form, so I won't bother you with thaty. The writing out the result, works, so you wont need that either...

Whats left is now the code, that opens the databse, gets the info, and saves the date. Here it is:

<%
dim streng1, streng2, sti, AccessDataBase, strSQL, rsconnection, rsRecordSet

sti = "c:\asp"
Streng1 = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ="
Streng2 = "\poll.mdb;UID=admin;PWD=;"
AccessDataBase = Streng1 & sti & Streng2

strSQL = "SELECT * FROM poll1"
Set rsConnection = Server.CreateObject("ADODB.Connection")
Set rsRecordSet = Server.CreateObject("ADODB.RecordSet")
rsConnection.Open AccessDataBase
rsRecordSet.Open strSQL, rsConnection, 2, 3


dim spq, count, formervalue
spq = Request.Form("spq")
formervalue = rsRecordSet(spq)
count = formervalue + 1


strSQL = "UPDATE poll1 SET " & spq & "='" & Count &"' WHERE row='1'"




'then I have deleted the part, writnig out the contents


rsRecordSet.Close
Set rsRecordSet = nothing
rsConnection.Close
Set rsConnection = nothing

%>
'

Thats it!

Does any of you, know what I am doing wrong? If you want, I can maíl you my files, and you cancheck it out on your own machine...

A lost
Casper

[Edited by hotcut on 10-20-2000 at 10:11 AM]

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Hmmm, your code seems a little strange, I would write it out the following way:

<?php
Dim rsConnection
   Dim rsRecordSet
   Dim spq
   Dim count
   Dim formervalue
   Dim strSQL

   spq
= Request.Form("spq")

  
Set rsConnection = Server.CreateObject("ADODB.Connection")
  
Set rsRecordSet = Server.CreateObject("ADODB.Recordset")
  
rsConnection = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\asp\poll.mdb;UID=admin;PWD=;"

  
strSQL = "UPDATE poll1 SET spq = spq + 1 WHERE row='1'"

  
rsRecordSet.Open strSQL, rsConnection, 2, 3

   rsRecordSet
.Close
   Set rsRecordSet
= nothing
   rsConnection
.Close
   Set rsConnection
= nothing
?>

It would help if we knew what your fields were called, do you have a field called row?

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Hmmm... You didnt understand it...

I suppose that whats confusing you is this:


sti = "c:\asp"
Streng1 = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ="
Streng2 = "\poll.mdb;UID=admin;PWD=;"
AccessDataBase = Streng1 & sti & Streng2

It is actually the same as saying:


AccessDataBase = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\asp\poll.mdb;UID=admin;PWD=;"

Maybe I will have to explain this too:


'1:
dim spq, count, formervalue
'2:
spq = Request.Form("spq")
'3:
formervalue = rsRecordSet(spq)
'4:
count = formervalue + 1

1: Here I define all the variables at once

2:getting the value from the form, wich will be: spq1, spq2 or spq3 This will later on be used, to define where in the databse I want to change something

3: Getting the old value, from the sell,´mathing the same name, as the asver was.

4: Adding "1" to the value, of the results.

That should ansver that. Do you get the idea, of THAT now? Else, I will try to explain that a bit better.

The code, you gave me, was filled with errors, but the idea was the same, as in my script.

You were asking of what cells I had in my database.

I have told that before in this thread, but I wont mind doing it again Smiling

I have the database called "poll.mdb" inside that database, I have 1 table, called "poll1" inside that table, I have the following:

             +-----------------------+
Field name:  |id | spq1 | spq2 | spq3|
             |-----------------------|
Field value: |1  | 3    | 1    | 2   |
             +-----------------------+
'

Thats it!

I dont think that you need more info... If you do, just ask me, and if you want, I can send you the intire script, including database, and all so that you can see you self.

I hope that someone in here can help me out...

Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

hotcut-

you keep missing this part

dim spq, count, formervalue
spq = Request.Form("spq")
formervalue = rsRecordSet(spq)
count = formervalue + 1

strSQL = "UPDATE poll1 SET " & spq & "='" & Count &"' WHERE row='1'"
<strong>rsRecordSet.Open strSQL, rsConnection, 2, 3 </strong>
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Hi there

I keep trying, and trying... but with no result!

The only thing, that I am sure that works, is the form; I get the ansver right, with the info I need!

I will [again]post some of my code [/again] so that you might see the error...

I will allso this time, try to explain all the variales, there functions and so on!

Here it goes:

<?php
dim AccessDataBase
, strSQL, dbconnection, rsRecordSet

<strong>'Here I define the first set of variables</strong>

    AccessDataBase = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\asp\poll.mdb;UID=admin;PWD=;"
<strong>'
modifying the variable "accessdatabse" to further use</strong>





   
strSQL = "SELECT * FROM poll1"
<strong>'choosing what table I want to use</strong>


Set dbConnection = Server.CreateObject("ADODB.Connection")
Set rsRecordSet = Server.CreateObject("ADODB.RecordSet")
<strong>'
Creating some standard connections</strong>

dbConnection.Open AccessDataBase
rsRecordSet
.Open strSQL, dbConnection, 2, 3
<strong>'opening some connections</strong>


dim spq, count, formervalue
<strong>'
defining a few more variables to further use</strong>

spq = Request.Form("spqnummer")

<
strong>'getting the value of "spqnummer" The values will be: spq1 or spq2 or spq3</strong>

count = rsRecordSet(spq) + 1
<strong>'
adding 1 to the former count, for the set line called "spqx" where x is the value from the lines above</strong>


strSQL = "UPDATE poll1 SET " & <strong>spq</strong> & "='" & Count &"' WHERE row='1'"
?>

'Here I am updating the table, where the first bold part is the value of the variable called "spq".
The cell is updated to the value of the variable called "count"
The row is something I actually doesnt undertsand how works, but it shoul tell the script, what row it is, according to the field called "id" which the numer 1

That was the code here.

I just hope that you see the ansver... I am feeling a bit lost here; Why doesnt the script work ? Mad

[hopefull]HELP?![hopefull]

Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

hotcut,

The thing I don't like about your code is that you're making two calls to the database just to update the poll. Your first call is to get the previous value so you can add 1 to it, then your second call is to save that new value to the poll, why not just do it in one step?

<?php


spq
= Request.Form("spqnummer")

AccessDataBase = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\asp\poll.mdb;UID=admin;PWD=;"

Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open AccessDataBase
Set rsRecordSet
= Server.CreateObject("ADODB.RecordSet")

With rsRecordSet
    
.ActiveConnection = dbConnection
    
.CursorType = 3 'adOpenKeyset
     .LockType = 2 '
adLockOptimistic
    
.Source = "Poll1"
    
.Filter = "WHERE id = 1"
    
.Open
End With

Select
Case spq
    
Case "spq1"
    
rsRecordSet.Fields("spq1") = rsRecordSet.Fields("spq1") + 1
    
Case "spq2"
    
rsRecordSet.Fields("spq2") = rsRecordSet.Fields("spq2") + 1
    
Case "spq3"
    
rsRecordSet.Fields("spq3") = rsRecordSet.Fields("spq3") + 1
    
Case Else
    
'error handling goes here
End Select

With rsRecordSet
     .Update
     .MoveFirst
     .Close
End With

Set rsRecordSet = nothing
dbConnection.Close
Set dbConnection = nothing
?>

That code makes more sense to me since it only makes a single call to the database.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Hi Peter

I tryed to implement your code to my script, but I got a lot of failures; The code I wrote before, was just a part of my script; I will allso need to make all the contents of the other fields into variables, a well! I didnt write that, maybe I should have done that, but I didnt thourght that it would be nessesary...

The problem IS in this line:

strSQL = "UPDATE poll1 SET " & spq & "='" & Count &"' WHERE row='1'"

I am not sure of what the problem actually is here, but I am not even sure if this line is activated! It seems like, nomatter what I write (allmost) in that line, the script doesnt repond to it!

My hope for a solution, is fading away... Sad

Can you see other problems in my script? Or maybe I should post the intire code here in this forum...

Casper

They have: 133 posts

Joined: Sep 2000

Wee are the champions weeeeee....... Wink

Finaly, I found the error! I am not sure, if that was what you ment Peter, but I tryed to only have 1 strSQL statement in every connection, and after a while, I made it work!!!

I could close the thread now, but naah, I think that it would be a shame Smiling First of all you probably want the solution, so I will offcorse give you that &~}

Ehhmm... New question Smiling How do I set a cookie? If it is hard to do, I will just leave it, but if it is posible, I would like to know:

1: How do I write a variable to a cookie on the users computer?

2: How do I get the same cookie back, in a avriable?

Ýou might think now, that I totaly forgot to give you the code, but I just wanted to get you all exited Smiling

Ok, like Christmas, you will first get the code when: ... Ohh what the f*** here it is: Smiling

dim spq
spq = Request.Form("spqnummer")

'getting the variables, needed further in the script!

dim streng1, streng2, sti, AccessDataBase
sti = "c:\asp"
Streng1 = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ="
Streng2 = "\poll.mdb;UID=admin;PWD=;"
AccessDataBase = Streng1 & sti & Streng2


dim strSQL, dbconnection, rsRecordSet
strSQL = "SELECT * FROM poll1"
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open AccessDataBase
Set rsRecordSet = Server.CreateObject("ADODB.RecordSet")
rsRecordSet.Open strSQL, dbConnection, 2, 3


dim count, spq1, spq2, spq3
count = rsRecordSet(spq) + 1
spq1 = rsRecordSet("spq1")*1
spq2 = rsRecordSet("spq2")*1
spq3 = rsRecordSet("spq3")*1


rsRecordSet.Close
Set rsRecordSet = nothing
dbConnection.Close
Set dbConnection = nothing

'connection determained

'making new copnnection, to use for the update

strSQL = "UPDATE poll1 SET " & spq & " = " & count
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open AccessDataBase
Set rsRecordSet = Server.CreateObject("ADODB.RecordSet")
rsRecordSet.Open strSQL, dbConnection, 2, 3

rsRecordSet.Close
Set rsRecordSet = nothing
dbConnection.Close
Set dbConnection = nothing

'determaining the connection
'

That simple, yet we used that much time on it...

Then I would like to thank Max and Peter for there help in this matter, I would never had come this far without your help! Maybe I should allso thank : http://hotwired.lycos.com/webmonkey/ for all there toturials, that allso helped me to better understanding, in this last fase; I found an FAQ where they had a link to: http://www.4guysfromrolla.com/webtech/faq/Databases/faq3.shtml which explained very good to me, how it works... Maybe Max should read this, they say what will happend if you drop the "WHERE" statement, very usefull indead!

My poll is finished, now all it ´needs is a bit shining up, and perhaps a little cookie, to veryfy if the user has allready signed it...

THHHHHHANK YOU!!!!

I ow you both one Laughing out loud

A lucky
Casper!!!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.