Solved

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

Posted on 2004-04-19
13
162 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

947 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

22 Experts available now in Live!

Get 1:1 Help Now