Convert VB to C#

We have this old code from an ASP website that we are moving over to ASP.NET C# - we are trying to make minimal changes to the old pages since it wasn't part of the contract but we need to swap this out to C# since all of the new stuff is in it.   I have part of it but not the loop piece.

Old code
 For a = 1 to Request.Form("propertyid").Count
strSQL = "Insert into property_assign (assigned_to, propertyid) VALUES ("
strSQL = strSQL & "'" & Request.Form("assigned_to") & "',"
strSQL = strSQL & "'" & Request.Form("propertyid")(a) & "')"

Open in new window


The start of my new code:
foreach (var Properties in Request("propertyid")) { 
            sql2 = "Insert into property_assign (assigned_to, propertyid) VALUES (@0, @1)";
            db.Execute(sql2, Request.Form("username"), Properties.propertyid);

Open in new window


I get Non-invocable member 'WebPageRenderingBase.Request' cannot be used like a method.
digitalwiseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
Use [] instead of () in C#.  So, for example, use

Request["propertyid"]

Open in new window


instead of

Request("propertyid")

Open in new window


You'll need to do the same with
Request.Form("username")

Open in new window

0
WilliamCommented:
Not a web guy here but -
Are you missing the count?

Request("propertyid")
or
Request("propertyid").Count
or
Request("propertyid").Count()
something like that maybe
0
digitalwiseAuthor Commented:
Ah yes!   That was dumb since i have written tons of code today - don't know why I missed it.   So now I get

 'char' does not contain a definition for 'propertyid' and no extension method 'propertyid' accepting a first argument of type 'char' could be found (are you missing a using directive or an assembly reference?)

var Properties in Request["propertyid"]

Open in new window


I am not sure how to write that - basically looking for each item in the list from the Request["propertyid"] form field.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

WilliamCommented:
Request.Form["propertyid"].Length
0
digitalwiseAuthor Commented:
BillyDvD - what is that replacing?
0
WilliamCommented:
Sorry - posted to soon - lol
You need to iterate 'something' that something was originaly the Count for "propertyid" -

So :
for (int i = 0; i < Request.Form["propertyid"].Length; i++)
{
       //---| Do you r string building here |---
}
0
WilliamCommented:
i may need to be 1 for the for loop instead of zero.....
0
digitalwiseAuthor Commented:
BillyDvD - how do I reference the value to save it though?   I need the value of each iteration.
0
WilliamCommented:
for ( int i = 0 ; i < this.Request.Form[ "propertyid" ].Length ; i++ )
            {
                string strSQL = "Insert into property_assign (assigned_to, propertyid) VALUES ('" + this.Request.Form[ "assigned_to" ] + "','" + this.Request.Form[ "propertyid" ][ i ] + "')";
                //---| Now use the string..... |---
            }

It is the [i] now - it was (a)

Open in new window

0
digitalwiseAuthor Commented:
That is giving me integers and not the actual value...

sql2 = "Insert into property_assign (assigned_to, propertyid) VALUES (@0, @1)";
                db.Execute(sql2, this.Request.Form["username"], this.Request.Form["propertyid"][i]);

Open in new window

0
digitalwiseAuthor Commented:
I just looked at this more closely - this is a comma-delimited list of items - they are longer than one character so the length thing isn't going to work.  IT looks like
Asdasd_123123, ASD_54123, FAS_2141...
0
WilliamCommented:
Not sure if this will help:

 string strSQL = string.Empty;

            if ( this.Request.Form[ "propertyid" ].Length > 0 )
                strSQL = "Insert into property_assign (assigned_to, propertyid) VALUES ('" + this.Request.Form[ "assigned_to" ] + "','" +
                     this.Request.Form[ "propertyid" ] + "')";

Open in new window

0
WilliamCommented:
Do you need to iterate each piece of the comma delimeted list?
I am not sure what you are trying to "get" from this loop.
If you had the input to the loop and the outputs pre code change - then we can reverse engineer this much easier.
0
digitalwiseAuthor Commented:
I need the values from the list because we are creating a record for each of the properties.    The code was super simple in VB...  

 For a = 1 to Request.Form("propertyid").Count
strSQL = "Insert into property_assign (assigned_to, propertyid) VALUES ("
strSQL = strSQL & "'" & Request.Form("assigned_to") & "',"
strSQL = strSQL & "'" & Request.Form("propertyid")(a) & "')"

Open in new window

0
WilliamCommented:
string strSQL = string.Empty;
            //---| Create an array of the comma delimeted parts |---
            string[ ] sa = this.Request.Form[ "propertyid" ].Split( new char[ ] { ',' } , StringSplitOptions.RemoveEmptyEntries );

            foreach ( var item in sa )
            {
                strSQL = "Insert into property_assign (assigned_to, propertyid) VALUES ('" + this.Request.Form[ "assigned_to" ] + "','" + item + "')";
                //---| Now use the string as during the next iteration it will be reset ..... |---
            }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WilliamCommented:
digitalwise - Just to let you know, I may not be available the rest of this evening. I may be able to pick this back up around 6AM CST though.

Thanks
BillyDvD
0
digitalwiseAuthor Commented:
This was perfect!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.