Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: vb string usage as a variable name


Message #1 by "ariel rodriguez" <arielmiami@m...> on Wed, 13 Feb 2002 15:24:03
I have the following text boxes is aspx



...

<input id="MyText1" type="text" runat="server"/>

<input id="MyText2" type="text" runat="server"/>

...



Then I want to populate a command parameter using:



Dim SelectCmd As String = "select * from mytable where name " & _ 

                          "= @MyText1 or name = "@MyText2" & _ ....



Then I have a loop:



For X = 0 to 9

    MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@MyText" & X, 

SqlDbType.NVarChar, 10))

    MyCommand.SelectCommand.Parameters("@MyText" & X).Value = (MyText & 

X).Value

Next X



The first line in the loop works ok but then when it gets to the second 

line it does not like the "= (MyText & X).Value" part.  I am trying to 

create a variable name on the fly.  Any ideas how to get this working?



Thanks before hand,

Ariel
Message #2 by "McCloy, Russell" <Russell.McCloy@B...> on Thu, 14 Feb 2002 08:23:58 +1100
Maybe if you setup your variable first as follows:

(im just guessing!)



========================================================================

For X = 0 to 9

    MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@MyText" & X, 

SqlDbType.NVarChar, 10))



  lsText = "@MyText" & X 	 '<< I added this



    MyCommand.SelectCommand.Parameters(lsText).Value = (lsText).Value

Next X

========================================================================



RuSs



-----Original Message-----

From: ariel rodriguez [mailto:arielmiami@m...]

Sent: Thursday, 14 February 2002 2:24 AM

To: ASP+

Subject: [aspx] vb string usage as a variable name





I have the following text boxes is aspx



...

<input id="MyText1" type="text" runat="server"/>

<input id="MyText2" type="text" runat="server"/>

...



Then I want to populate a command parameter using:



Dim SelectCmd As String = "select * from mytable where name " & _ 

                          "= @MyText1 or name = "@MyText2" & _ ....



Then I have a loop:



For X = 0 to 9

    MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@MyText" & X, 

SqlDbType.NVarChar, 10))

    MyCommand.SelectCommand.Parameters("@MyText" & X).Value = (MyText & 

X).Value

Next X



The first line in the loop works ok but then when it gets to the second 

line it does not like the "= (MyText & X).Value" part.  I am trying to 

create a variable name on the fly.  Any ideas how to get this working?



Thanks before hand,

Ariel




Message #3 by Shannon Stewart <sstewart_59102@y...> on Wed, 13 Feb 2002 14:31:43 -0800 (PST)
You could try using this:



MyCommand.SelectCommand.Parameters("@MyText" &

X).Value = CType((MyText & X), textbox).Text



This should retrieve the actual textbox.  I'm not at

my development machine, so I didn't test it first. 

But at least it might give you something to work from.



sstewart



--- "McCloy, Russell" <Russell.McCloy@B...>

wrote:

> Maybe if you setup your variable first as follows:

> (im just guessing!)

> 

>

========================================================================

> For X = 0 to 9

>     MyCommand.SelectCommand.Parameters.Add(New

> SqlParameter("@MyText" & X, 

> SqlDbType.NVarChar, 10))

> 

>   lsText = "@MyText" & X 	 '<< I added this

> 

>     MyCommand.SelectCommand.Parameters(lsText).Value

> = (lsText).Value

> Next X

>

========================================================================

> 

> RuSs

> 

> -----Original Message-----

> From: ariel rodriguez [mailto:arielmiami@m...]

> Sent: Thursday, 14 February 2002 2:24 AM

> To: ASP+

> Subject: [aspx] vb string usage as a variable name

> 

> 

> I have the following text boxes is aspx

> 

> ...

> <input id="MyText1" type="text" runat="server"/>

> <input id="MyText2" type="text" runat="server"/>

> ...

> 

> Then I want to populate a command parameter using:

> 

> Dim SelectCmd As String = "select * from mytable

> where name " & _ 

>                           "= @MyText1 or name 

> "@MyText2" & _ ....

> 

> Then I have a loop:

> 

> For X = 0 to 9

>     MyCommand.SelectCommand.Parameters.Add(New

> SqlParameter("@MyText" & X, 

> SqlDbType.NVarChar, 10))

>     MyCommand.SelectCommand.Parameters("@MyText" &

> X).Value = (MyText & 

> X).Value

> Next X

> 

> The first line in the loop works ok but then when it

> gets to the second 

> line it does not like the "= (MyText & X).Value"

> part.  I am trying to 

> create a variable name on the fly.  Any ideas how to

> get this working?

> 

> Thanks before hand,

> Ariel





> $subst('Email.Unsub').

> 





$subst('Email.Unsub').





__________________________________________________

Do You Yahoo!?

Send FREE Valentine eCards with Yahoo! Greetings!

http://greetings.yahoo.com

Message #4 by "sstewart" <sstewart_59102@y...> on Thu, 14 Feb 2002 02:48:18
Ok, so I wasn't quite there yet.  The code below should work.



For X = 0 to 9

     MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@MyText" & 

X, 

 SqlDbType.NVarChar, 10))

     MyCommand.SelectCommand.Parameters("@MyText" & X).Value = CType

(Me.FindControls("MyText" & X), Textbox).Text

Next X



Hopefully this will work for you,



sstewart



> I have the following text boxes is aspx

> 

> ...

> <input id="MyText1" type="text" runat="server"/>

> <input id="MyText2" type="text" runat="server"/>

> ...

> 

> Then I want to populate a command parameter using:

> 

> Dim SelectCmd As String = "select * from mytable where name " & _ 

>                           "= @MyText1 or name = "@MyText2" & _ ....

> 

> Then I have a loop:

> 

> For X = 0 to 9

>     MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@MyText" & 

X, 

> SqlDbType.NVarChar, 10))

>     MyCommand.SelectCommand.Parameters("@MyText" & X).Value = (MyText & 

> X).Value

> Next X

> 

> The first line in the loop works ok but then when it gets to the second 

> line it does not like the "= (MyText & X).Value" part.  I am trying to 

> create a variable name on the fly.  Any ideas how to get this working?

> 

> Thanks before hand,

> Ariel

  Return to Index