Link to home
Start Free TrialLog in
Avatar of radhakrishan
radhakrishan

asked on

VB.NET to C#

Hello Experts,

I am just trying to move a project from VB.NET to C# (With very little knowledge of C#)

Could anyone pls answer the following questions for me:

1. In my web.config I have:

<appSettings>
      <!--Utilities Keys-->
      <add key="NAGTYUtilities.ConnectionString" value="server=xxxxxx; uid=nitinsharma; pwd=$onityGenius1; database=QueryDev"/>            
       </appSettings>
</configuration>

How do I access it in other files to get the connectionstring, at present I am doing like shown below but that gives me error:
                     SqlConnection sqlconn = new SqlConnection();
                sqlconn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings(1);

2. How Do I write the following VB Line into C# (I get very confused with "" and '')

 Booking.Attributes.Add("onclick", "javascript:window.open('BookingPage.aspx?@cid=" + Trim(DropDownList1.SelectedValue) + "&@ctext=" + Trim(DropDownList1.SelectedItem.Text) + "&@dday=" + Trim(Calendar1.SelectedDate) + "&@id=0" & "','_blank','status=yes,toolbar=no,width=550,height=370');")

Any help would b much appreciated.
Ave a gud day!
ASKER CERTIFIED SOLUTION
Avatar of GavinMannion
GavinMannion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of radhakrishan
radhakrishan

ASKER


sqlconn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("NAGTYUtilities.ConnectionString");
Error I recieve while doing above is:
'System.Configuration.ConfigurationSettings.AppSettings' denotes a 'property' where a 'method' was expected


Secondly, Even removing the & from it would look like:

 Booking.Attributes.Add("onclick", "javascript:window.open('BookingPage.aspx?@cid=" + Trim(DropDownList1.SelectedValue) + "&@ctext=" + Trim(DropDownList1.SelectedItem.Text) + "&@dday=" + Trim(Calendar1.SelectedDate) + "&@id=0"','_blank','status=yes,toolbar=no,width=550,height=370');")

It comes with loads of errors of expecting ";" ....

Hey radhakrishan ,

"( )" won't work in c# you'll have to use "[ ]" brackets. That is the reason you are getting the error.

Harshit Sheth
Hi Harshit,

So should be like this:


 Booking.Attributes.Add["onclick", "javascript:window.open['BookingPage.aspx?@cid=" + Trim[DropDownList1.SelectedValue] + "&@ctext=" + Trim[DropDownList1.SelectedItem.Text] + "&@dday=" + Trim[Calendar1.SelectedDate] + "&@id=0"','_blank','status=yes,toolbar=no,width=550,height=370'];"]

That got errors of its own...


My Exact VB Code is:
 Booking.Attributes.Add("onclick", "javascript:window.open('BookingPage.aspx?@cid=" + Trim(DropDownList1.SelectedValue) + "&@ctext=" + Trim(DropDownList1.SelectedItem.Text) + "&@dday=" + Trim(Calendar1.SelectedDate) + "&@id=0" & "','_blank','status=yes,toolbar=no,width=550,height=370');")

which needs change to C#.


Thanks.
I think the problem is with the Querystring input bcoz if I do
this.Booking.Attributes.Add("onclick","javascript:window.open('BookingPage.aspx' ,'_blank','status=yes,toolbar=no,width=550,height=370')");

that works fine.

But I want 4 querystring to go with it:

@cid = DropdownList.SelectedValue.Trim()
@ctext = Dropdownlist.SelectedItem.Text.Trim()
@day = Calendar1.SelectedDate
@id = 0

If someone could tell me how to send those query strings that would b great!

Firstly as harshits said, I left the ( brackets around the connection string instead of putting the square ones...

Make it
sqlconn.ConnectionString =System.Configuration.ConfigurationSettings.AppSettings["NAGTYUtilities.ConnectionString"].ToString();

On the second part after you took away the ampersand you forgot to put the semicolon right at the end.

ALL C# statements must end with a semi colon
Hi,

AS you mentioned doing this
 this.Booking.Attributes.Add("onclick", "javascript:window.open('BookingPage.aspx?@cid=" + Trim(DropDownList1.SelectedValue) + "&@ctext=" + Trim(DropDownList1.SelectedItem.Text) + "&@dday=" + Trim(Calendar1.SelectedDate) + "&@id=0"','_blank','status=yes,toolbar=no,width=550,height=370');");

Brings up 18 errors of either ";" Expected or "," invalid character.......

If I remove all the querystrings this seems to work fine for me, but i need all those.

Could you pls write the same statement with the querystrings i mentioned above and i could check if it really matches, bcoz surely the prob is in there!

Unfortunately I don't have a dev environment on hand to test this in otherwise I would....

Okay looking again it looks like you have an extra " after @id=0

Take that away..

You should only have "'s before javascript... just before the end closing brackets and then on each side of + something +
Hi,


It works fine, avent tested but error free atleast!

(I have split the pts bcoz of both of u guys help!)

Cheers!!