Results 1 to 34 of 34

Thread: Want your feedback on my first object in C# (with sample solution now!)

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Want your feedback on my first object in C# (evolving)

    What do you mean by a "shared property"? Are you using "shared" in the VB.NET sense, which is "static" in C#? Also, what class are you using this in? I would think that this should be an abstract method of the base class that you override in the derived PreparedStatement classes.
    Code:
        public abstract class Parent
        {
            public abstract IDbConnection GetConnection();
        }
    
        public class Child1 : Parent
        {
            public override IDbConnection GetConnection()
            {
                return new OleDbConnection();
            }
        }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Want your feedback on my first object in C# (evolving)

    Yup, I meant abstract, have you tried your sample code if it works? I think I have also something along such line and encountered an error, can't test for now since I don't have IDE here... And I am thinking of probably using like the ff but encountered an error also , I'm just freehand typing it, don't know if it's 100% correct...

    Code:
    public class Child
    {	
    	private OleDbConnection conn1 = new OleDbConnection;
    	private SqlConnection conn2 = new SqlConnection();
    	private IDbConnection conn3;
    
    	public void SetConnection(int pType)
    	{
    		switch
    		{
    			case is 1:
    				conn3 = conn1;					
    				break;
    			case is 2"
    				conn3 = conn2;
    				break;
    
    			default;
    				conn3 = conn1
    				break;
    		}
    	}
    
    	public IDbConnection GetConnection()
    	{
    		return conn3;		
    	}
    
    }
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width