Execute stored procedures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anniejacob
    New Member
    • Feb 2007
    • 14

    Execute stored procedures

    Hi,
    i have made a dynamic form in C# where in the textboxes r made dynamically .
    so now i have too run some stored procedures.
    normally when u write code for the textboxes associated with it as

    SqlCommand mysql1 = new SqlCommand("usp _calDiameter", coon);
    mysql1.CommandT ype = CommandType.Sto redProcedure;
    mysql1.Connecti on = coon;
    mysql1.Paramete rs.Add(new SqlParameter("@ Flowrate", Flowrate));
    mysql1.Paramete rs.Add(new SqlParameter("@ SpecificVelocit y", SpecificVelocit y));
    mysql1.Paramete rs.Add(new SqlParameter("@ PSFID", PSFID));


    but the prob is that im makin textboxes dynamically so if anyone could help me with the code to execute stored procedures using this dynamic textboxes


    hope u people could help me out soon


    Bye........
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    How are you creating the textbox dynamically? If you will create it like this
    you will be able to access its value

    system.web.ui.w ebcontrols textbox name=system.web .ui.webcontrols .textbox()

    Comment

    • anniejacob
      New Member
      • Feb 2007
      • 14

      #3
      Originally posted by shweta123
      Hi,

      How are you creating the textbox dynamically? If you will create it like this
      you will be able to access its value

      system.web.ui.w ebcontrols textbox name=system.web .ui.webcontrols .textbox()


      im using a windows application .
      i created textboxes using

      TextBox textboxes = new TextBox();
      this.Controls.A dd(textboxes);

      can u help me to execute the stored procedures further

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        TextBox textboxes = new TextBox();
        textboxes.Name = "textbox1"

        this.Controls.A dd(textboxes);

        SqlCommand mysql1 = new SqlCommand("usp _calDiameter", coon);
        mysql1.CommandT ype = CommandType.Sto redProcedure;
        mysql1.Connecti on = coon;


        'Assign value of textbox in a parameter

        Dim p1 as new SqlParameter
        p1.Value=this.c ontrols(""textb ox1").Text
        ............... ........
        ............... ......
        mysql1.Paramete rs.Add(p1)

        Comment

        • anniejacob
          New Member
          • Feb 2007
          • 14

          #5
          hi,
          in the last post u had given the code as
          'Assign value of textbox in a parameter

          Dim p1 as new SqlParameter
          p1.Value=this.c ontrols(""textb ox1").Text
          ............... ........
          ............... ......
          mysql1.Paramete rs.Add(p1)


          but then im makin dynamic textboxes so then how 2 pass parameters 4 each.
          so then i will have to use some general statement that will take all the parameters 4 as many textboxes present on that form.


          In the form im makin, i have to pass some input values that will execute some stored procedures n will give out the output in the same form in textboxes


          so i have many stored procedures also that is to b executed in the same form which will calculate the values 4 the textboxes.

          so can anyone help me sort it out.

          Comment

          • shweta123
            Recognized Expert Contributor
            • Nov 2006
            • 692

            #6
            Hi,

            If "textbox1" is one of your textboxes.You can check for it as

            for i=0 to me.controls.cou nt
            if me.controls(i). Name = ""textbox1" then
            'Assign it to the paramter
            p1.value= me.controls(i). Text
            end if
            next

            Comment

            Working...