Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 updating database [ASP], another prob...SQL statement..pls help!!

views
     
TSgracenalec
post Feb 5 2006, 05:02 PM, updated 20y ago

Getting Started
**
Junior Member
200 posts

Joined: Feb 2005
<%
Dim adoCon 'Holds the Database Connection Object
Dim rsUpdateEntry 'Holds the recordset for the record to be updated
Dim strSQL 'Holds the SQL query for the database
Dim lngRecordNo 'Holds the record number to be updated


lngRecordNo = CLng(Request.Form("User_ID"))
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("forum.mdb")

strSQL = "SELECT * FROM profile WHERE User_ID = '" & lngRecordNo & "'"
rsUpdateEntry.Open strSQL, adoCon
rsUpdateEntry.CursorType = 2
rsUpdateEntry.LockType = 3

rsUpdateEntry.Fields("Name") = Request.Form("name")
rsUpdateEntry.Update


rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

'Return to the update select page incase another record needs deleting
Response.Redirect "update_select.asp"
%>

i'm having prob wif this...i'm trying to update my database..juz like when u click 'edit profile' in lowyat forum. after chging the details in a textbox and clicking a button to submit the chges, chges will b made in de datbase..how can i do tat?

Script error detected at line 14.
Source line: rsUpdateEntry.Open strSQL, adoCon
Description: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

pls help

This post has been edited by gracenalec: Feb 6 2006, 09:30 PM
SincerePrayer
post Feb 5 2006, 08:37 PM

love to pray
Group Icon
Elite
1,120 posts

Joined: Jun 2005
gracenalec,

Instead of select the record out and update it, you may want to try to issue an SQL command to directly update the record. This approach will increase the performance for your server.

CODE
strSQL = "UPDATE profile "
strSQL = strSQL & "SET [Name] = '" & Replace(Request.Form("name"), "'", "''") & "' "
strSQL = strSQL & "WHERE User_ID = '" & lngRecordNo & "'"



Happy Coding smile.gif
sinister
post Feb 6 2006, 01:13 PM

Enthusiast
*****
Senior Member
963 posts

Joined: Jan 2003
yup..

i wouldn't recommend u use dat way, better to use SQL command, it's faster and more efficient..

Better learn ur INSERT,UPDATE sql statement.
TSgracenalec
post Feb 6 2006, 09:27 PM

Getting Started
**
Junior Member
200 posts

Joined: Feb 2005
okok..thx a lots guys..my problem is solved wink.gif

unfortunately i have another problem...wat is my SQL statement when i wanna use the LIKE statement. I did this: SQL= "SELECT * FROM posts WHERE message LIKE" &% search %

it keeps on giving me error..i wonder if this is the correct SQL statement used in asp..btw...search is actually a variable...wat i'm trying to do is accept user's input from a textbox and store in to variable-search.

pls correct me..thxx
lmcckl
post Feb 6 2006, 09:29 PM

Getting Started
**
Junior Member
50 posts

Joined: Dec 2005
From: KL


where is line 14 smile.gif

anyway, likely the problem have something to do with null value
TSgracenalec
post Feb 6 2006, 09:52 PM

Getting Started
**
Junior Member
200 posts

Joined: Feb 2005
yea...that error is done dy..but the sql statement of the prob i stated above isn't done sad.gif pls help
SincerePrayer
post Feb 6 2006, 10:13 PM

love to pray
Group Icon
Elite
1,120 posts

Joined: Jun 2005
gracenalec,

You may want to try the following code
CODE

strSQL = "SELECT * FROM posts WHERE message LIKE ''%" & search & "%''"



Happy Coding smile.gif
TSgracenalec
post Feb 6 2006, 10:40 PM

Getting Started
**
Junior Member
200 posts

Joined: Feb 2005
hurm...not working sad.gif
sinister
post Feb 7 2006, 09:54 AM

Enthusiast
*****
Senior Member
963 posts

Joined: Jan 2003
grace.. could u publish ur not working code so dat we can have a look
one.good.guy
post Feb 8 2006, 02:00 PM

Observer
*****
Senior Member
856 posts

Joined: Feb 2005



try this:

strSQL = "SELECT * FROM posts WHERE message LIKE '%" & search & "%' "

I think there's one too many apostrophe ' in the code given by sincereprayer.

This post has been edited by one.good.guy: Feb 8 2006, 02:02 PM
lmcckl
post Feb 11 2006, 04:27 PM

Getting Started
**
Junior Member
50 posts

Joined: Dec 2005
From: KL


User_ID field is a integer field or string field ? if it a integer field pls try this

CODE

SELECT * FROM profile WHERE User_ID = " & lngRecordNo


btw, i just remove the single quote

This post has been edited by lmcckl: Feb 11 2006, 04:28 PM
lmcckl
post Feb 11 2006, 04:34 PM

Getting Started
**
Junior Member
50 posts

Joined: Dec 2005
From: KL


QUOTE(gracenalec @ Feb 6 2006, 09:27 PM)
okok..thx a lots guys..my problem is solved wink.gif

unfortunately i have another problem...wat is my SQL statement when i wanna use the LIKE statement. I did this: SQL= "SELECT * FROM posts WHERE message LIKE" &% search %

it keeps on giving me error..i wonder if this is the correct SQL statement used in asp..btw...search is actually a variable...wat i'm trying to do is accept user's input from a textbox and store in to variable-search.

pls correct me..thxx
*
MS access have diffrent syntax for like statement. if remember it correctly it is something like this

CODE
SELECT * FORM posts WHERE message LIKE #search#


Please try the query with ms access if posible and ms access help file got example that might help you solve your problem


shinchan^^
post Feb 13 2006, 09:11 AM

K66
*********
All Stars
21,256 posts

Joined: Jan 2003
From: Pekopon


oh ya miscosft access use different format

 

Change to:
| Lo-Fi Version
0.0194sec    0.46    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 09:10 AM