Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Should we escape ' when building command text?
Message
De
03/01/2008 14:11:56
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
ASP.NET
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01278630
Message ID:
01279321
Vues:
12
This message has been marked as a message which has helped to the initial question of the thread.
>In run-time that variable @EventVal already declared

Well, yeah ... if you have more than one Item selected in your List, then you'll be adding that parameter more than once. Yeah, that's not gonna work that way. Try this:
            ListItem Item;
            string ParmName;
            for (int i=0; i < this.lsbEvntTargetPop.Items.Count; i++)
            {
                Item = this.lsbEvntTargetPop.Items[i];
                if (Item.Selected)
                {
                    ParmName = "@EventVal" + i.ToString();
                    Command.CommandText += "\nINSERT INTO EventTargets VALUES(@EvID," + ParmName + ")";
                    Command.Parameters.AddWithValue(ParmName , Item.Value);
                }
            }
~~Bonnie




>>What error are you getting? Is it at run-time or compile-time?
>>
>>~~Bonnie
>>
>
>In run-time that variable @EventVal already declared (something like that, I'm trying to work on another problem right now).
>
>
>>>Can I use the same technique within a loop or I should go John's way?
>>>
>>>I tried to change the original code using string.Format to
>>>
>>>            foreach (ListItem Item in this.lsbEvntTargetPop.Items)
>>>            {
>>>                if (Item.Selected)
>>>                {
>>>                    Command.CommandText += "\nINSERT INTO EventTargets VALUES(@EvID,@EventVal)";
>>>                    Command.Parameters.AddWithValue("@EventVal", Item.Value);
>>>
>>>                }
>>>            }
>>>
>>>but I'm getting an error. How should I change this?
>>>
>>>Thanks again for your help.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform