Click here to Skip to main content
15,898,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Gareth H24-Jan-08 0:30
Gareth H24-Jan-08 0:30 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Varad_Rajan24-Jan-08 0:32
Varad_Rajan24-Jan-08 0:32 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Varad_Rajan24-Jan-08 0:34
Varad_Rajan24-Jan-08 0:34 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Anthony Mushrow24-Jan-08 1:03
professionalAnthony Mushrow24-Jan-08 1:03 
QuestionHow to Change or Generate a file with Owner using .NET 1.1 Pin
Ninerocky23-Jan-08 23:29
Ninerocky23-Jan-08 23:29 
Questionhow to add .rpt and .cri extensions in IIS (windows 2000 with crystal reports 9 installed on the same) Pin
here2learn23-Jan-08 23:06
here2learn23-Jan-08 23:06 
GeneralSqlConnection and scope Pin
Dewald23-Jan-08 22:40
Dewald23-Jan-08 22:40 
GeneralRe: SqlConnection and scope Pin
N a v a n e e t h23-Jan-08 23:03
N a v a n e e t h23-Jan-08 23:03 
Dewald wrote:
I suppose one solution would be to pass the SqlConnection as a parameter to the function that will be working on it but for some reason I don't like that.


Why ? That is the easy method. You can do it like
using (SqlConnection mySqlConnection = new SqlConnection(...))
{
   myFunc1(ref mySqlConnection );
   myFunc2(ref mySqlConnection );
}


If you don't want to pass the connection, try the following.
private SqlConnection mySqlConnection = null;
using (mySqlConnection = new SqlConnection(...))
{
   myFunc1();
   myFunc2();
}
In this mySqlConnection is declared as private in the class. So you will get access to all methods.

When I have created a DAL, I implemented IDisposable interface and provided a Dispose() method which clears my SQLConnection instance. It will be instantiated in the constructor. So it would look like
public class MyDAL : IDisposable
{
   SQLConnection mySqlConnection = null;
   public MyDAL()
   {
       mySqlConnection = new SqlConnection(...);
   }

   public void Dispose()
   {
        //Dispose connection here
   } 
}

You can call this like
using(MyDAL dal = new MyDAL())
{
    //Call MyFun1,MyFun2
}
In the above code, you haven't passed any parameters to the methods.

Hope it helps


All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia

My Website | Ask smart questions


QuestionCopy Contents in Excel Pin
mohankatari23-Jan-08 22:00
mohankatari23-Jan-08 22:00 
GeneralRe: Copy Contents in Excel Pin
Paul Conrad24-Jan-08 7:03
professionalPaul Conrad24-Jan-08 7:03 
Questionhow can i access the xml file in the in richtextbox in c#.net? Pin
samidhas23-Jan-08 21:01
samidhas23-Jan-08 21:01 
AnswerRe: how can i access the xml file in the in richtextbox in c#.net? Pin
N a v a n e e t h23-Jan-08 23:04
N a v a n e e t h23-Jan-08 23:04 
Generalstatus bar Pin
mahenputta23-Jan-08 20:11
mahenputta23-Jan-08 20:11 
GeneralRe: status bar Pin
DaveyM6924-Jan-08 0:58
professionalDaveyM6924-Jan-08 0:58 
GeneralRe: status bar Pin
mahenputta24-Jan-08 1:36
mahenputta24-Jan-08 1:36 
GeneralRe: status bar Pin
DaveyM6924-Jan-08 1:45
professionalDaveyM6924-Jan-08 1:45 
GeneralRe: status bar Pin
mahenputta24-Jan-08 1:51
mahenputta24-Jan-08 1:51 
QuestionHow to make an auto-update tool? Pin
hio7723-Jan-08 19:42
hio7723-Jan-08 19:42 
GeneralRe: How to make an auto-update tool? Pin
Giorgi Dalakishvili23-Jan-08 21:17
mentorGiorgi Dalakishvili23-Jan-08 21:17 
GeneralRe: How to make an auto-update tool? Pin
N a v a n e e t h23-Jan-08 23:05
N a v a n e e t h23-Jan-08 23:05 
Questionhow to save ? Pin
samidhas23-Jan-08 19:15
samidhas23-Jan-08 19:15 
GeneralRe: how to save ? Pin
N a v a n e e t h23-Jan-08 23:07
N a v a n e e t h23-Jan-08 23:07 
GeneralURL monitoring Pin
Adeel Chaudhry23-Jan-08 17:26
Adeel Chaudhry23-Jan-08 17:26 
GeneralRe: URL monitoring Pin
Paul Conrad23-Jan-08 17:53
professionalPaul Conrad23-Jan-08 17:53 
GeneralRe: URL monitoring Pin
Adeel Chaudhry23-Jan-08 18:01
Adeel Chaudhry23-Jan-08 18:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.