Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can any one tell me what is wrong with my coding?

Posted on 2004-04-19
13
Medium Priority
?
168 Views
Last Modified: 2006-11-17
Hi Experts,
I'm having problem with this chunk of code I've written. Looks ok to me but it doesnt work the way I want it. Here the code is

Set rsMBR_CODE = Server.CreateObject("ADODB.Recordset")
  rsMBR_CODE.Open "Select * From members Where MBR_CODE='" & Replace(sMBR_CODE,"'","''") & "'", cnn, 2, 3
  If rsMBR_CODE.EOF Then
        rsMBR_CODE.AddNew
      rsMBR_CODE("MBR_CODE") = sMBR_CODE
    rsMBR_CODE.Update
  Else
    Response.Redirect "URL to another page"
  End If

the field type is Number. everytime I try to add a new member code it appears as a Zero. Help me please.
0
Comment
Question by:ahmad_fidentia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 2

Expert Comment

by:ileanarc
ID: 10865910
Hi,

I do not understand why do you treat MBR_CODE as a string if the field type is Number.

You should get an error when you try to open the recordset, saying that the data types do not match.

Ileana.
0
 

Author Comment

by:ahmad_fidentia
ID: 10865980
Hello Ileana,
thanx for the quick response. can you tell me how I am supposed to treat MBR_CODE if not as a string. how is the correct way to redefine it and turn it into an integer?
0
 
LVL 2

Expert Comment

by:somchaiu
ID: 10866269
Your code could be adjust to

Set rsMBR_CODE = Server.CreateObject("ADODB.Recordset")
  rsMBR_CODE.Open "Select * From members Where MBR_CODE=" & sMBR_CODE, cnn, 2, 3
  If rsMBR_CODE.EOF Then
       rsMBR_CODE.AddNew
     rsMBR_CODE("MBR_CODE") = sMBR_CODE
    rsMBR_CODE.Update
  Else
    Response.Redirect "URL to another page"
  End If

But I think the code to produce sMBR_CODE is the problem.
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 2

Expert Comment

by:ileanarc
ID: 10866437
Yeap,

I tend to agree with somchaiu. In order to see the value of the sMBRC variable, place

Response.Write(sMBR_CODE)

right above "Set rsMBR_CODE".... and delete the "respose.redirect ..." from the end of the asp page (if the page redirects)

One of the problems could be a redefinition of the variable.

Ileana.
0
 
LVL 3

Expert Comment

by:zapthedingbat
ID: 10867056
what is the value of sMBR_CODE when it is assigned to MBR_CODE ?

at a guess I'd say this is a datatype issue. T
ry converting sMBR_CODE to an int before assigning it

rsMBR_CODE("MBR_CODE") = cInt(sMBR_CODE)
rsMBR_CODE.Update
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10867164
Just like to make an observation...

A Replace() is being performs - this is normally done to make it SQL safe - this also implies its of DataType Text
=========================================================================
 rsMBR_CODE.Open "Select * From members Where MBR_CODE='" & Replace(sMBR_CODE,"'","''") & "'", cnn, 2, 3
 

You are comparing MBR_CODE & sMBR_CODE which obviously returns a matching record, you then update it with the same value - this means that no change has been made to the record
========================================================================================================================
rsMBR_CODE("MBR_CODE") = sMBR_CODE
rsMBR_CODE.Update

All-in-all this snippet of code updates a field with the same value making it appear as tho nothing has happened.
0
 
LVL 2

Expert Comment

by:ileanarc
ID: 10871314
Lord McFly,

You are right about the first thing - the replace function - but I do not agree with your second statement.

There's an "AddNew" method before the assignement "rsMBR_CODE("MBR_CODE") = sMBR_CODE". The logic is the following: if there is no record with the same MBR_Code, than  add a new one. Am I missing sth?

Thanks,
Ileana.
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10874684
Sorry missed that :)

Ok, you say its not working - what do you mean by this...

• Is procudes an error
• Executes fine but the record isn't in the DB

Also - you mention that it doesn't do what you want it to do - just to be clear, you want to add a new record if it does not exists - where you expecting it to do anything else?
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10885461
Do you need any more assistance on this question?
0
 

Author Comment

by:ahmad_fidentia
ID: 10896051
Okay Experts,
I really appreciate your responses and comments. I found out where my mistake was. and I corrected it right away. now it's working fine exactly as far as my concern. here I'll tell you guys what the problem was:
I opened members table once to see if the member id already existed. if it did not exist then it could add a new one. right in the bottom of that code I opened the same table  trying to  add to the other fields except for member id. but what it was doing was, it was adding to the other fields meantime it replaced the value of member id  to zero. so I had to change the whole concept of my coding. thanks again.
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10958966
As you answered you own question I would suggest you request a refund and close this question - cheers.

I answered my question myself. What do I do?
---------------------------------------------------------------
http://www.experts-exchange.com/Web/help.jsp#hi70
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11975840
Submitted to PAQ with points refunded (50)

DarthMod
Community Support Moderator
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question