Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2009, 01:14 PM
Registered User
 
Join Date: Jul 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default Remove part of database field?

Hello,

In one database field I have a list of employee id numbers that need to approve a request. Ex. 101&102&103

I use an array to split this field and get each one separately. I'm trying to remove part of the above string based on who has approved it.

For example, the db would originally have: 101&102&103

Let's say approver 102 signed in and approved the request, I now want to update the database to only have 101&103

I saw a Remove property, is it possible to use that?

(The reason why I use a string with multiple id numbers is because there could be anywhere from 0 to 4 approvers, so I'd rather not have separate database fields for each.)

Thanks in advance.
 
Old August 10th, 2009, 01:45 PM
Registered User
 
Join Date: Jul 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Okay I think I have a better way to go about it but I need help with doing a string builder.

The way I'm going to do this, is a new string will be created and the approver that is signed in will not be included.

So this is what I've got:
Code:
string[] BOGApprovers = lblBOGApprovers.Text.Split(newchar[] { '&' });
StringBuilder builder = newStringBuilder();
foreach (string BOG in BOGApprovers)
{
//get signed in BOG, if not signed in, add to string
if (BOG != emp)
{
builder.Append( ?????? )
}
}
Now my question is how do I append the string to look like "101&103" ??
 
Old August 10th, 2009, 02:08 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Code:
public void Approve(string employeeId)
{
   // this value would be normally obtained from the database
   string approvalsPending = "101&102&103";
 
   string[] toApprove = approvalsPending.Split('&');
   string[] toRemove = {employeeId};
   string[] remainingToApprove = toApprove.Except(toRemove).ToArray();
 
   string putBackInDb = String.Join("&", remainingToApprove);
 
   // code here to put the new string back into the db
}
Here, if you pass in 102, as in Approve("102"), the result will be 101&103.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
jenbuh (August 10th, 2009)
 
Old August 10th, 2009, 02:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hello.

Two things...

There are a better way to store this. You use another table that holds only the Id of the request and the Id of the employee (you will have several rows for every request).
That will be the standard way to do it.

Anyway.. Isn't there a Replace function in the String class?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
jenbuh (August 10th, 2009)
 
Old August 10th, 2009, 02:36 PM
Registered User
 
Join Date: Jul 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Oh this is great! I didn't even think to do that and it makes things much easier when determining how many approvals are still required. Thank you so much!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract part of field from inconsistent data Roly Reefer Access VBA 4 March 31st, 2005 09:25 AM
Seperating Date part from a datetime field ctranjith SQL Server 2000 2 October 25th, 2004 06:42 AM
Remove Hard Returns from Memo Field darinsee Classic ASP Databases 4 July 7th, 2004 04:08 PM
Index Part of Field owain Access 4 October 2nd, 2003 09:34 AM
Index Part of Field owain SQL Language 3 September 29th, 2003 09:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.