Solved

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

Posted on 2004-04-19
13
166 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

635 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