Solved

How to rename an object?

Posted on 2003-12-04
4
263 Views
Last Modified: 2010-04-16
Look at the following code:
I want to rename SQLdbConn to dnConn and it fail to compile.  Dosent recognise the new name...
How should i do it?

      public SqlConnection SQLdbConn;
            
                  public Connection(string conType, string conStr)
                  {
                                 this.openConnection(conType, conStr);
                  }
                  public void openConnection(string conType, string conStr)
                  {
                        //Case resasign dbConn and open connection
                        switch(conType)      
                        {        
                              case "sqlclient":
                                    // use constructor to open the connection
                                    SQLdbConn = dbConn;
                                    dbConn = new SqlConnection(conStr);
                                    dbConn.Open();                        
                                    break;

0
Comment
[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
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
jj819430 earned 250 total points
ID: 9877499
public SqlConnection SQLdbConn;
         
               public Connection(string conType, string conStr)
               {
                              this.openConnection(conType, conStr);
               }
               public void openConnection(string conType, string conStr)
               {
                    //Case resasign dbConn and open connection
                    switch(conType)      
                    {        
                         case "sqlclient":
                              // use constructor to open the connection
                              SQLdbConn = dbConn;   // you are using dbConn here
                              dbConn = new SqlConnection(conStr);  // you are declaring dbConn here
                              dbConn.Open();                    
                              break;

Just switch the two around. so that your switch looks like this:

 switch(conType)      
                    {        
                         case "sqlclient":
                              // use constructor to open the connection
                             
                              dbConn = new SqlConnection(conStr);  // you are declaring dbConn here
                              SQLdbConn = dbConn;   // you are using dbConn here
                              dbConn.Open();                    
                              break;
0
 

Author Comment

by:Yann de Champlain, PMP
ID: 9877609
Thanks.

Stupid I was...
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9878470
eh, everyone does the same stuff. Half the time people just need to have a fresh set of eyes look at it.
0
 

Author Comment

by:Yann de Champlain, PMP
ID: 9878538
yep you right
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change to file doesn't show up 16 93
asp web application 3 56
Problem to copy file 14 92
RestClient.cs fails at (HttpWebResponse)request.GetResponse()) 4 53
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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