Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2007, 04:52 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Activator.CreateInstance for DB Provide!

I followed the Activator.CreateInstance method in the book but I can't get this core piece to work. I have a MSAccess db provider for testing purposes but keep getting a compiling error. Can someone help me as to what I'm doing wrong?

namespace Company.DAL
{
    public abstract class ConfigProvider : DataAccess
    {
        static private ConfigProvider _instance = null;
        static public ConfigProvider Instance
        {
            get
            {
                if (_instance == null)
                    _instance = (ConfigProvider)Activator.CreateInstance(
                     Type.GetType(Company.DAL.MdbClient.MdbConfig ));
                return _instance;
            }
        }

        public abstract string GetConfigValue(ConfigXML site, string id, string name);
    }
}

Then in the "interchangable" data access layer I have this:
namespace Company.DAL.MdbClient
{
    public class MdbConfig : ConfigProvider
    {
        public override string GetConfigValue(ConfigXML site, string id, string name)
        {
            try
            {
                string connString = WebConfigurationManager.ConnectionStrings[site.SettingsTable.ConnectionStringName].ConnectionString;
                string sqlCmd = "SELECT Value FROM " + site.SettingsTable.TableName + " WHERE UCASE(id)='" + id.ToUpper() + "' AND UCASE(name)='" + name.ToUpper() + "'";

                using (OleDbConnection conn = new OleDbConnection(connString))
                {
                    OleDbCommand cmd = new OleDbCommand(sqlCmd, conn);
                    conn.Open();

                    object obj = cmd.ExecuteScalar();

                    if (obj.Equals(System.DBNull.Value))
                        return string.Empty;
                    else
                        return (string)obj;
                }
            }
            catch
            {
                return string.Empty;
            }
        }
    }
}

Then in my aspx page I'm calling the method like this:
Response.Write(ConfigProvider.Instance.GetConfigVa lue(domain, "company", "Address1"));

But I get this error:
Compiler Error Message: CS0119: 'Company.DAL.MdbClient.MdbConfig' is a 'type', which is not valid in the given context
Source Error:
Line 21: if (_instance == null)
Line 22: _instance = (ConfigProvider)Activator.CreateInstance(
Line 23: Type.GetType(Company.DAL.MdbClient.MdbConfig));
Line 24: return _instance;
Line 25: }
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please provide solution prasanta2expert SQL Language 4 September 24th, 2007 08:56 AM
Problem with Activator.CreateInstance karveajit .NET Framework 1.x 0 May 11th, 2006 01:05 AM
CreateInstance method problem(urgent).. Srikanth_nd C# 0 June 16th, 2005 01:16 AM
Why provide both books chrisda BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 February 24th, 2005 08:13 PM
how to provide synchronisation to the access of db sajeeshtk Beginning VB 6 0 April 26th, 2004 02:22 AM



All times are GMT -4. The time now is 06:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.