Click here to Skip to main content
16,019,876 members
Home / Discussions / C#
   

C#

 
GeneralRe: .GetFiles(?) Pin
HahnTech26-Jul-06 12:17
HahnTech26-Jul-06 12:17 
QuestionEnterprise Library 2.0 and Database Trace Listener Pin
osamahmirza26-Jul-06 9:18
osamahmirza26-Jul-06 9:18 
QuestionCommunicating between forms Pin
jerrymei26-Jul-06 9:04
jerrymei26-Jul-06 9:04 
AnswerRe: Communicating between forms Pin
led mike26-Jul-06 9:11
led mike26-Jul-06 9:11 
Questiontrygetvalue? Please help Pin
honeyman_can26-Jul-06 8:46
honeyman_can26-Jul-06 8:46 
AnswerDo you have access to a computer? Pin
Ennis Ray Lynch, Jr.26-Jul-06 9:12
Ennis Ray Lynch, Jr.26-Jul-06 9:12 
AnswerRe: trygetvalue? Please help Pin
led mike26-Jul-06 9:15
led mike26-Jul-06 9:15 
QuestionADOX making me crazy, please help Pin
perry5926-Jul-06 8:45
perry5926-Jul-06 8:45 
Im trying to create an access database with ADOX. It is to contain 3 tables,
each with a primary and foreign key and a one-to-one relationship between
each table.
I have no problem creating and populating the tables, no problem adding indexes to each table (one index is also a primary key). When I try to add primary keys
to any tables that do not already have one, it bombs out.
I've scoured everything I can find on ADOX (most of its VB) and nothing helps and
some examples I found were bad or confusing.
I'm also not sure if simply creating the primary/foreign keys will create a relationship of if there is something else I must do.
I've posted my code below with comments on the problem areas, I appreciate
any help (while I still have hair left) !
-------------------------------------------------------------------------------
<br />
/// <summary><br />
        /// Create new database file<br />
        /// </summary><br />
        /// <br />
        public static void CreateDb(string fileName)<br />
        {<br />
            // append function prototype<br />
            // Append(object Item, ADOX.KeyTypeEnum Type, object Column, string RelatedTable, string RelatedColumn)<br />
<br />
            ADOX.CatalogClass cat = new ADOX.CatalogClass();<br />
            ADOX.Table tblNew = new ADOX.Table();<br />
            ADOX.Index tblIdx = new ADOX.Index();<br />
            ADOX.Key tblKey = new ADOX.Key();<br />
<br />
            // Create database and add tables<br />
            try<br />
            {<br />
                cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Jet OLEDB:Engine Type=5");<br />
                // Create the CUSTOMERS table<br />
                tblNew.Name = "Customers";<br />
                tblNew.ParentCatalog = cat;<br />
                tblNew.Columns.Append("CustomerID", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("MachineType", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Name", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Address", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("City", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("State", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Zip", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Country", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Status", ADOX.DataTypeEnum.adWChar, 50);<br />
                cat.Tables.Append(tblNew);<br />
                tblNew = null;<br />
<br />
                // Create the DRAWINGS table<br />
                tblNew = new ADOX.Table();<br />
                tblNew.Name = "Drawings";<br />
                tblNew.ParentCatalog = cat;<br />
                tblNew.Columns.Append("CustomerID", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("DrawingNumber", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("DrawingTitle", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("DrawingDate", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("FileName", ADOX.DataTypeEnum.adWChar, 255);<br />
                cat.Tables.Append(tblNew);<br />
                tblNew = null;<br />
               <br />
                // Create the REVISIONS table<br />
                tblNew = new ADOX.Table();<br />
                tblNew.Name = "Revisions";<br />
                tblNew.ParentCatalog = cat;<br />
                tblNew.Columns.Append("DrawingNumber", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("RevisionLetter", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("RevisionDate", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("RevisionNote", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("RevBy", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("CheckBy", ADOX.DataTypeEnum.adWChar, 50);<br />
                tblNew.Columns.Append("Key", ADOX.DataTypeEnum.adWChar, 50);<br />
                cat.Tables.Append(tblNew);<br />
                tblNew = null;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Utilities.InfoMessageBox(ex.Message);<br />
            }<br />
<br />
            // Add reference indexes<br />
            try<br />
            {<br />
                // Create index column in customers table with unique values.<br />
                // This column is also the primary key for this table.<br />
                tblNew = cat.Tables["Customers"];<br />
                tblIdx.Name = "CustomerIndex";<br />
                tblIdx.Unique = true;<br />
                tblIdx.PrimaryKey = true;<br />
                tblIdx.Columns.Append("CustomerID", tblNew.Columns["CustomerID"].Type, tblNew.Columns["CustomerID"].DefinedSize);<br />
                // Append the index to table.<br />
                tblNew.Indexes.Append((object)tblIdx, null);<br />
                tblIdx = null;<br />
                tblNew = null;<br />
                tblIdx = new ADOX.Index();<br />
<br />
                // Create index column in drawings table with unique values.<br />
                tblNew = cat.Tables["Drawings"];<br />
                tblIdx.Name = "DrawingsIndex";<br />
                tblIdx.Unique = true;<br />
                tblIdx.Columns.Append("DrawingNumber", tblNew.Columns["DrawingNumber"].Type, tblNew.Columns["DrawingNumber"].DefinedSize);<br />
                // Append the index to table.<br />
                tblNew.Indexes.Append((object)tblIdx, null);<br />
                tblIdx = null;<br />
                tblNew = null;<br />
                tblIdx = new ADOX.Index();<br />
<br />
                // Create index column in revisions table with unique values.<br />
                tblNew = cat.Tables["Revisions"];<br />
                tblIdx.Name = "RevisionsIndex";<br />
                tblIdx.Unique = true;<br />
                tblIdx.Columns.Append("Key", tblNew.Columns["Key"].Type, tblNew.Columns["Key"].DefinedSize);<br />
                // Append the index to table.<br />
                tblNew.Indexes.Append((object)tblIdx, null);<br />
                tblIdx = null;<br />
                tblNew = null;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Utilities.InfoMessageBox(ex.Message);<br />
            }<br />
<br />
            // Does adding foreign/primary keys create a relationship, or do I have to do<br />
            // something else?<br />
<br />
            // Add foreign keys<br />
            try<br />
            {<br />
                tblNew = cat.Tables["Drawings"];<br />
                tblKey = new ADOX.Key();<br />
                tblKey.Name = "2nd";<br />
                tblKey.Type = KeyTypeEnum.adKeyForeign;<br />
                tblKey.RelatedTable = "Customers";<br />
                tblKey.DeleteRule = RuleEnum.adRINone;<br />
                tblKey.UpdateRule = RuleEnum.adRINone;<br />
                tblKey.Columns.Append("CustomerID", tblNew.Columns["CustomerID"].Type, tblNew.Columns["CustomerID"].DefinedSize);<br />
                tblKey.Columns["CustomerID"].RelatedColumn = "CustomerID";<br />
                // Do I not append the key to the table here?<br />
                tblKey = null;<br />
                tblNew = null;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Utilities.InfoMessageBox(ex.Message);<br />
            }<br />
<br />
            // Add other primary keys<br />
            try<br />
            {<br />
                tblNew = cat.Tables["Drawings"];<br />
                tblKey = new ADOX.Key();<br />
                tblKey.Name = "1st";<br />
                tblKey.Type = KeyTypeEnum.adKeyPrimary;<br />
                tblKey.Columns.Append("CustomerID", tblNew.Columns["CustomerID"].Type, tblNew.Columns["CustomerID"].DefinedSize);<br />
                //next line throws exception from HRESULT<br />
                tblNew.Keys.Append((object)tblKey, ADOX.KeyTypeEnum.adKeyPrimary, (object)tblNew.Columns["CustomerID"], "Drawings", "CustomerID");<br />
                tblKey = null;<br />
                tblNew = null;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Utilities.InfoMessageBox(ex.Message);<br />
            }<br />
<br />
            // Clean up<br />
            if (tblIdx != null)<br />
                tblIdx = null;<br />
            if (tblKey != null)<br />
                tblKey = null;<br />
            if (tblNew != null)<br />
                tblNew = null;<br />
            if (cat != null)<br />
                cat = null;<br />
        }

QuestionGetting DataGridView checkbox checked event when it happens.... Pin
LongRange.Shooter26-Jul-06 8:44
LongRange.Shooter26-Jul-06 8:44 
AnswerRe: Getting DataGridView checkbox checked event when it happens.... Pin
led mike26-Jul-06 8:48
led mike26-Jul-06 8:48 
QuestionDetermining whether .Net 2.0 is installed or not? Pin
wasife26-Jul-06 7:36
wasife26-Jul-06 7:36 
Questionbuild 2003 from 2005 Pin
spin vector26-Jul-06 7:15
spin vector26-Jul-06 7:15 
AnswerRe: build 2003 from 2005 Pin
Steve Maier26-Jul-06 7:34
professionalSteve Maier26-Jul-06 7:34 
GeneralRe: build 2003 from 2005 Pin
spin vector26-Jul-06 7:54
spin vector26-Jul-06 7:54 
QuestionRegEx in C# to split on two delimiters Pin
Master Toothless One26-Jul-06 7:08
Master Toothless One26-Jul-06 7:08 
AnswerRe: RegEx in C# to split on two delimiters Pin
Dustin Metzgar26-Jul-06 8:20
Dustin Metzgar26-Jul-06 8:20 
GeneralRe: RegEx in C# to split on two delimiters Pin
Master Toothless One26-Jul-06 9:30
Master Toothless One26-Jul-06 9:30 
AnswerRe: RegEx in C# to split on two delimiters Pin
BoneSoft26-Jul-06 12:02
BoneSoft26-Jul-06 12:02 
Questiontutorial with datagridview Pin
simsen26-Jul-06 7:02
simsen26-Jul-06 7:02 
AnswerRe: tutorial with datagridview Pin
simsen26-Jul-06 8:39
simsen26-Jul-06 8:39 
GeneralRe: tutorial with datagridview Pin
spin vector26-Jul-06 8:55
spin vector26-Jul-06 8:55 
AnswerRe: tutorial with datagridview Pin
simsen26-Jul-06 22:44
simsen26-Jul-06 22:44 
Questionhow to render a huge report in realtime (<1 minute) Pin
Razvan Dimescu26-Jul-06 7:02
Razvan Dimescu26-Jul-06 7:02 
AnswerRe: how to render a huge report in realtime (<1 minute) Pin
Ennis Ray Lynch, Jr.26-Jul-06 7:06
Ennis Ray Lynch, Jr.26-Jul-06 7:06 
AnswerRe: how to render a huge report in realtime (<1 minute) Pin
LongRange.Shooter26-Jul-06 8:50
LongRange.Shooter26-Jul-06 8:50 

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.