25. oktober 2005 - 22:40Der er
5 kommentarer og 1 løsning
Opret SQL-database i runtime
Hej der ude
Er der nogen der ved eller kender et link til hvordan man opretter en database og tilhørende tabellet på SQL-server via VB6. Således at man via et program i runtiem kan oprette de ønsket databaser m.v.
Koden ovenfor virker uden tvivl. Men SQL server har jo sit helt eget objekt hieraki som du kan få fat i via SQL-DMO. Eksempel.
Først set reference til SQL-DMO.
Dim oSQLServer As New SQLDMO.SQLServer Dim bConnected As Boolean Dim oDatabase As New SQLDMO.Database Dim oDBFileData As New SQLDMO.DBFile Dim oLogFile As New SQLDMO.LogFile Dim tableCategories As New SQLDMO.Table Dim colCategoryID As New SQLDMO.Column Dim colCategoryName As New SQLDMO.Column Dim colDescription As New SQLDMO.Column Dim colPicture As New SQLDMO.Column
' Get the Northwind database. Note: Create and connect of SQLServer ' object used is not illustrated in this example. Set oDatabase = oSQLServer.Databases("Northwind")
' Populate the Column objects to define the table columns. colCategoryID.Name = "CategoryID" colCategoryID.Datatype = "int" colCategoryID.Identity = True colCategoryID.IdentityIncrement = 1 colCategoryID.IdentitySeed = 1 colCategoryID.AllowNulls = False
' Name the table, then set desired properties to control eventual table ' construction. tableCategories.Name = "Categories" tableCategories.FileGroup = "PRIMARY" tableCategories.TextFileGroup = "fgNorthwindTxtImg"
' Add populated Column objects to the Columns collection of the ' Table object. tableCategories.Columns.Add colCategoryID tableCategories.Columns.Add colCategoryName tableCategories.Columns.Add colDescription tableCategories.Columns.Add colPicture
' Create the table by adding the Table object to its containing ' collection. oDatabase.Tables.Add tableCategories
Hej der ude. Lidt tricky med SQL-DMO referencen og installationen heraf. Men jeg kunne bruge dit forslag i vid udstrækning og points går derfor til dig.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.