?
Solved

VB.NET to C#

Posted on 2006-06-23
10
Medium Priority
?
436 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:radhakrishan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 15

Accepted Solution

by:
GavinMannion earned 1000 total points
ID: 16967662
sqlconn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("NAGTYUtilities.ConnectionString");

Should work .... if nto what error do you get...

I cannot see anythign wrong with your second line of code except you are missing the ending semicolon ;

what I see it :), after @id=0" you have an ampersand & for no reason, take away the following " & "

It should work then
0
 
LVL 3

Assisted Solution

by:harshits
harshits earned 400 total points
ID: 16967708
Hi,

Here is answer to your first question. The code for fetching a appsetting value from web.config is

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

I was not able to get your second query. If possible could you provide me the original piece of vb.net code which you are trying to convert to c#. May be then It might be a little more clear.

Harshit Sheth

0
 

Author Comment

by:radhakrishan
ID: 16967726

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 ";" ....

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:harshits
ID: 16967786
Hey radhakrishan ,

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

Harshit Sheth
0
 

Author Comment

by:radhakrishan
ID: 16967842
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.
0
 

Author Comment

by:radhakrishan
ID: 16967940
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!

0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16968052
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
0
 

Author Comment

by:radhakrishan
ID: 16968116
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!

0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16968423
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 +
0
 

Author Comment

by:radhakrishan
ID: 16968477
Hi,


It works fine, avent tested but error free atleast!

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

Cheers!!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question