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.Connec tionString " 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.Confi gurationSe ttings.App Settings(1 );
2. How Do I write the following VB Line into C# (I get very confused with "" and '')
Booking.Attributes.Add("on click", "javascript:window.open('B ookingPage .aspx?@cid =" + Trim(DropDownList1.Selecte dValue) + "&@ctext=" + Trim(DropDownList1.Selecte dItem.Text ) + "&@dday=" + Trim(Calendar1.SelectedDat e) + "&@id=0" & "','_blank','status=yes,to olbar=no,w idth=550,h eight=370' );")
Any help would b much appreciated.
Ave a gud day!
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.Connec
</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.Confi
2. How Do I write the following VB Line into C# (I get very confused with "" and '')
Booking.Attributes.Add("on
Any help would b much appreciated.
Ave a gud day!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hey radhakrishan ,
"( )" won't work in c# you'll have to use "[ ]" brackets. That is the reason you are getting the error.
Harshit Sheth
"( )" won't work in c# you'll have to use "[ ]" brackets. That is the reason you are getting the error.
Harshit Sheth
ASKER
Hi Harshit,
So should be like this:
Booking.Attributes.Add["on click", "javascript:window.open['B ookingPage .aspx?@cid =" + Trim[DropDownList1.Selecte dValue] + "&@ctext=" + Trim[DropDownList1.Selecte dItem.Text ] + "&@dday=" + Trim[Calendar1.SelectedDat e] + "&@id=0"','_blank','status =yes,toolb ar=no,widt h=550,heig ht=370'];" ]
That got errors of its own...
My Exact VB Code is:
Booking.Attributes.Add("on click", "javascript:window.open('B ookingPage .aspx?@cid =" + Trim(DropDownList1.Selecte dValue) + "&@ctext=" + Trim(DropDownList1.Selecte dItem.Text ) + "&@dday=" + Trim(Calendar1.SelectedDat e) + "&@id=0" & "','_blank','status=yes,to olbar=no,w idth=550,h eight=370' );")
which needs change to C#.
Thanks.
So should be like this:
Booking.Attributes.Add["on
That got errors of its own...
My Exact VB Code is:
Booking.Attributes.Add("on
which needs change to C#.
Thanks.
ASKER
I think the problem is with the Querystring input bcoz if I do
this.Booking.Attributes.Ad d("onclick ","javascr ipt:window .open('Boo kingPage.a spx' ,'_blank','status=yes,tool bar=no,wid th=550,hei ght=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!
this.Booking.Attributes.Ad
that works fine.
But I want 4 querystring to go with it:
@cid = DropdownList.SelectedValue
@ctext = Dropdownlist.SelectedItem.
@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.Conf igurationS ettings.Ap pSettings[ "NAGTYUtil ities.Conn ectionStri ng"].ToStr ing();
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
Make it
sqlconn.ConnectionString =System.Configuration.Conf
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
ASKER
Hi,
AS you mentioned doing this
this.Booking.Attributes.Ad d("onclick ", "javascript:window.open('B ookingPage .aspx?@cid =" + Trim(DropDownList1.Selecte dValue) + "&@ctext=" + Trim(DropDownList1.Selecte dItem.Text ) + "&@dday=" + Trim(Calendar1.SelectedDat e) + "&@id=0"','_blank','status =yes,toolb ar=no,widt h=550,heig ht=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!
AS you mentioned doing this
this.Booking.Attributes.Ad
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 +
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 +
ASKER
Hi,
It works fine, avent tested but error free atleast!
(I have split the pts bcoz of both of u guys help!)
Cheers!!
It works fine, avent tested but error free atleast!
(I have split the pts bcoz of both of u guys help!)
Cheers!!
ASKER
sqlconn.ConnectionString = System.Configuration.Confi
Error I recieve while doing above is:
'System.Configuration.Conf
Secondly, Even removing the & from it would look like:
Booking.Attributes.Add("on
It comes with loads of errors of expecting ";" ....