Avatar billede reds2001 Nybegynder
13. juni 2002 - 09:58 Der er 11 kommentarer og
1 løsning

VB 6 - ADO - Access

Jeg programmere i VB 6 og har en Access2000 database. Jeg benytter ADO og her er spørgsmålet så:
Hvordan sætter jeg tabellernes properties fra VB applikation(eksempelvis 'allow zero lenght=Yes)
Avatar billede kichian Nybegynder
13. juni 2002 - 10:54 #1
Du skal bruge ADOX. Det bliver installeret sammen med ADO, så det er bare at komme i gang.
Avatar billede alexandersen Nybegynder
13. juni 2002 - 13:11 #4
Du siger at du arbejder med en almindelig Access Database... hvorfor ikke bare gøre det på forhånd ???
Avatar billede reds2001 Nybegynder
13. juni 2002 - 16:18 #5
Terry>>Der er en masse om adox, men ikke noget der løser mit problem så vidt jeg kan se.
alexandersen>>Jeg skal være istand til at oprette hele databasefilen inclusiv struktur inde fra min applikation.
Avatar billede terry Ekspert
13. juni 2002 - 16:28 #6
Actually you should be able to create your tables with SQL commands
Avatar billede tubber Juniormester
15. juni 2002 - 18:34 #7
Jeg ville nu lave det hvor alle felter i databasen tillader "Zero Length"
og kode om brugeren må eller ikke må.

Hvis han ikke må kunne det se sådan ud :
If Text1.Text = "" then
    MsgBox = Text1.Caption + " må ikke være tomt!"
Else:
    Tilføj data i databasen
End If

/Tubber
Avatar billede tubber Juniormester
21. juni 2002 - 21:00 #8
Jeg mener det er smartest at bestemme og test i din VB kode
om der er Zero length, og om programmet tillader det, da du
ellers kan resikere at skulle fange fejl fra databasen, ellers
skal man jo kun samle fejl op i VB.
Avatar billede terry Ekspert
21. juni 2002 - 21:09 #9
CREATE TABLE Statement
Description

Creates a new table.

Note  The Microsoft Jet database engine doesn't support the use of CREATE TABLE, or any of the DDL statements, with non-Microsoft Jet database engine databases. Use the DAO Create methods instead.

Syntax

CREATE TABLE table (field1 type [(size)] [NOT NULL] [index1] [, field2 type [(size)]
ú [NOT NULL] [index2] [, ...]] [, CONSTRAINT multifieldindex [, ...]])

The CREATE TABLE statement has these parts

Part
Description




table
The name of the table to be created.

field1, field2
The name of field or fields to be created in the new table. You must create at least one field.

type
The data type of field in the new table.

size
The field size in characters (Text and Binary fields only).

index1, index2
A CONSTRAINT clause defining a single-field index. See the CONSTRAINT clause topic for more information on how to create this index.

multifieldindex
A CONSTRAINT clause defining a multiple-field index. See the CONSTRAINT clause topic for more information on how to create this index.



Remarks  Use the CREATE TABLE statement to define a new table and its fields and field constraints. If NOT NULL is specified for a field, then new records are required to have valid data in that field.

A CONSTRAINT clause establishes various restrictions on a field, and can be used to establish the primary key. You can also use the CREATE INDEX statement to create a primary key or additional indexes on existing tables.

You can use NOT NULL on a single field, or within a named CONSTRAINT clause that applies to either a single field or to a multiple-field named CONSTRAINT. However, you can apply the NOT NULL restriction only once to a field, or a run-time error occurs.
See Also  ALTER TABLE statement, CONSTRAINT clause, CREATE INDEX statement, CreateTableDef method ("DAO Language Reference"), DROP statement.

Example

This example creates a new table called ThisTable with two Text fields.

Sub CreateTableX1()

    Dim dbs As Database

    ' Modify this line to include the path to Northwind
    ' on your computer.
    Set dbs = OpenDatabase("Northwind.mdb")

    ' Create a table with two text fields.
    dbs.Execute "CREATE TABLE ThisTable " _
        & "(FirstName TEXT, LastName TEXT);"

    dbs.Close

End Sub
This example creates a new table called MyTable with two Text fields, a Date/Time field, and a unique index made up of all three fields.

Sub CreateTableX2()

    Dim dbs As Database

    ' Modify this line to include the path to Northwind
    ' on your computer.
    Set dbs = OpenDatabase("Northwind.mdb")

    ' Create a table with three fields and a unique
    ' index made up of all three fields.
    dbs.Execute "CREATE TABLE MyTable " _
        & "(FirstName TEXT, LastName TEXT, " _
        & "DateOfBirth DATETIME, " _
        & "CONSTRAINT MyTableConstraint UNIQUE " _
        & "(FirstName, LastName, DateOfBirth));"

    dbs.Close

End Sub
This example creates a new table with two Text fields and an Integer field. The SSN field is the primary key.

Sub CreateTableX3()

    Dim dbs As Database

    ' Modify this line to include the path to Northwind
    ' on your computer.
    Set dbs = OpenDatabase("Northwind.mdb")

    ' Create a table with three fields and a primary
    ' key.
    dbs.Execute "CREATE TABLE NewTable " _
        & "(FirstName TEXT, LastName TEXT, " _
        & "SSN INTEGER CONSTRAINT MyFieldConstraint " _
        & "PRIMARY KEY);"

    dbs.Close

End Sub
Example (Microsoft Access)

To try the following examples in Microsoft Access, first create a new query in the Northwind sample database. Close the Show Table dialog box without specifying a table or query. Switch to SQL view, paste an individual example into the SQL window, and run the query.


--------------------------------------------------------------------------------
Warning These examples makes changes to the Northwind sample database. Before beginning, you may wish to make a backup copy of the sample database.


--------------------------------------------------------------------------------
The following example creates a new table with two Text fields:

CREATE TABLE FirstTable (FirstName TEXT, LastName TEXT);
The next example creates a new table with two Text fields, a Date/Time field, and a unique index made up of all three fields:

CREATE TABLE SecondTable (FirstName TEXT,
LastName TEXT, DateOfBirth DATETIME,
CONSTRAINT MyTableConstraint UNIQUE (FirstName, LastName, DateOfBirth));
The following example creates a new table with two Text fields and an Integer Number field. The SSN field is the primary key.

CREATE TABLE ThirdTable (FirstName TEXT, LastName TEXT, SSN INTEGER
CONSTRAINT MyFieldConstraint PRIMARY KEY);


Contact Us  |  E-Mail this Page  |  MSDN Flash Newsletter 
© 2002 Microsoft Corporation. All rights reserved.  Terms of Use  Privacy Statement  Accessibility
Avatar billede terry Ekspert
21. juni 2002 - 21:12 #10
You DO NOT need to use ADOX to create tables it is streight forward SQL.
This example was found by entering "create table" in the serach field of the link I gave in my answer above.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadocodeexamples.asp

and there are more where that came from :o)
Avatar billede reds2001 Nybegynder
29. august 2002 - 08:06 #11
jeg synes ikke at jeg har fået valuta for pengene denne gang men thanx anyway.
Avatar billede terry Ekspert
29. august 2002 - 08:32 #12
hi reds2001>What is the problem?
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester