Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 November 27th, 2007, 12:28 PM
Authorized User
 
Join Date: Nov 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamically Parameters.Add for storedProc

Hi, the following doesn't seems to want to work for me, any ideas? is it even possible to dynamically add Parameters for t-sql, as such ? Thanks

Code:
using (SqlConnection connection = new SqlConnection(basic.config.Configuration.ConnectionInfo))
{


  SqlCommand cmd = new SqlCommand("sp_MCpage1", connection);
  cmd.CommandType = CommandType.StoredProcedure;

  // Convert Request.Form Collection to Hashtable
  HttpContext htc = HttpContext.Current;
  Hashtable htFormData = new Hashtable();
         foreach (string sForm in htc.Request.Form.Keys)
         {
         htFormData[sForm] = replacing.ReplaceEscapeChars(htc.Request.Form[sForm].ToString());
         cmd.Parameters.Add("@" + htFormData[sForm], SqlDbType.NVarChar).Value = htFormData[sForm];
         }

   try
   {
     connection.Open();
..................

..............
 
Old November 27th, 2007, 12:32 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

"Hi, the following doesn't seems to want to work for me"

How so? What doesn't work? Is there an error?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 27th, 2007, 02:41 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I suspect it might be because there is other stuff in Request.Form you probably don't want to pass to the stored procedure, such as the VIEWSTATE and other hidden fields.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
How add data into DataGrid dynamically [email protected] C# 2005 1 October 24th, 2007 03:27 AM
dynamically add new controls to a page vhrao Javascript 2 October 22nd, 2004 12:29 AM
Dynamically Add input tags Jstmehr4u3 Javascript How-To 2 July 29th, 2003 04:03 AM





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