Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Should we escape ' when building command text?
Message
From
31/12/2007 14:07:43
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
ASP.NET
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01278630
Message ID:
01278695
Views:
17
This message has been marked as a message which has helped to the initial question of the thread.
Bonnie,

PMFJI...

>
>tplEntry = string.Format("INSERT INTO Programs2Times (" +
>                "[ProgramID],[TimeOfProgram],[EndTime],[Fee],[VolunteerFee],[VolunteersReq],[Canceled]" +
>                ",[Facilitator]) VALUES({0},'{{0}} {1}','{{0}} {2}', " +
>                "{3}, {4}, {5}, 0, '{6}')\n", ProgramID, StartTime, EndTime, this.txtbProgFee.Text,
>                VolFee, this.txtbProgVolReq.Text, this.txtbPrgFacilitator.Text);
>
>and appended later in the loop.
>
>How can I apply Parameters here?


This is how I do it...Put your fields into a hashtable like this:
Hasttable ht = new Hashtable
ht.Add(ProgramID)
ht.ADd(StartTime)
ht.Add(EndTime)
ht.Add(this.txtbProgFee.Text)
ht.Add(VolFee)
ht.Add(this.txtbProgVolReq.Text)
ht.Add(this.txtbPrgFacilitator.Text)
Then create your insert statement:
INSERT INTO Programs2Times ([ProgramID],[TimeOfProgram],[EndTime],[Fee],[VolunteerFee],[VolunteersReq],[Canceled], [Facilitator]) VALUES (@p1, @p2, @p3, @p4,@p5, @p6, @p7)
Create your command object, add the insert string as text, and add the parameters to your command object:
       /// <summary>
        /// 
        /// </summary>
        /// <param name="parameterHash"></param>
        /// <returns></returns>
        private IDbCommand AddParametersToCommandFromHash(IDbCommand command, Hashtable parameterHash)
        {
            if (parameterHash != null)
            {
                foreach (DictionaryEntry entry in parameterHash)
                {
                    command.Parameters.Add(_provider.CreateParameter((string)entry.Key, entry.Value));

                }
            }

            return command;
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform