Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to rename an object?

Posted on 2003-12-04
4
Medium Priority
?
271 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
Question by:Yann de Champlain
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
jj819430 earned 1000 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
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
ID: 9878538
yep you right
0

Featured Post

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!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline

782 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