0
private void QueryDBSchema()
    {
        // Schema information for the current database connection.
        DataTable schema;

        // Loop counter.
        int loop = 0;

        // Clean up the menu so the menu item does not hang while this function  executes.
        this.Refresh();


            // Instantiate an OleDbConnection object.
        using (OleDbConnection oleDbConnection = new    OleDbConnection("Provider=SQLOLEDB;Password=sa123;User ID=sa;Data Source=mukesh;Initial Catalog=Medi;"))
            {
                try
                {
                    // Open the connection.
                    oleDbConnection.Open();

                    // Retrieve the Table objects.
                        schema =    oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "table" });

                    // Store the table names in the object collection.
                    for (loop = 0; loop < schema.Rows.Count; loop++)
                    {
                        objects.Add(schema.Rows[loop].ItemArray[2].ToString());
                    }
                }
                catch (Exception e)
                {
                   // Messages.BadConnection(e);
                }
            }

    }

This function for getting table name in objects list.

        // Instantiate the objects collection.
        this.objects = new Collection<string>();
        QueryDBSchema();

        // Gather each of the selected items (if any) into a collection object.
        foreach (string item in this.objects)
          {
          //This should be like this
          // "item" obj = new "item";

          }

in foreach loop i want to create class object with string saved in item value.How this possible in c# also same name class is exits in different namespace and i want to assign the object to another same class in different namespace and call function named like save in obj1.

such as

// "item" obj1 = new "item"; // "Item" obj2 = new "item";

obj1=obj2; obj1.Save();

mukesh
  • 1
  • 1
    Is this what you are asking? http://stackoverflow.com/questions/223952/c-sharp-create-an-instance-of-a-class-from-a-string?rq=1 – Daniel Kelley Jun 05 '14 at 12:27
  • 1
    Maybe this would be served with an ORM + Domain Models: http://www.orm.net/overview.html + http://msdn.microsoft.com/en-us/magazine/ee236415.aspx – drew_w Jun 05 '14 at 12:30
  • Do you have `Type` stored in database as a `string`? And you want to create object of that type and call `Save()` method of it? Regarding namespaces, you will have to save *fully qualified name* of type, to be able to correctly resolve conflicts: `"Namespace.Type"` or even `"Assembly@Namespace.Type"` (not sure about `@`). – Sinatr Jun 05 '14 at 12:45

1 Answers1

0

Use

ObjectHandle handle = Activator.CreateInstance("YourAssemblyName_String", "Item");

Item obj = (Item)handle.Unwrap();

skmic
  • 79
  • 1
  • 9