Solved

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

Posted on 2004-04-19
13
161 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
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…
The viewer will learn how to count occurrences of each item in an array.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now