859 863




Visual Basic 6 Black Book:Working With Database Objects In Code
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




DAO: Adding Fields To A TableDef Object
How do you add fields to a DAO TableDef object? You can use that object’s CreateField method to do that, passing that method the name of the new field and a constant indicating that field’s type:


TableDef.CreateField( FieldName, FieldType)


Here are the constants specifying the possible field types:


•  dbBigInt
•  dbBinary
•  dbBoolean
•  dbByte
•  dbChar
•  dbCurrency
•  dbDate
•  dbDecimal
•  dbDouble
•  dbFloat
•  dbGUID
•  dbInteger
•  dbLong
•  dbLongBinary (OLE object)
•  dbMemo
•  dbNumeric
•  dbSingle
•  dbText
•  dbTime
•  dbTimeStamp
•  dbVarBinary

Let’s see an example to make this clearer. In the previous topic, we created a TableDef object named td for the daocode example project (see the first topic in this chapter), and now we can add two fields to that object, which we declare in an array named fields of type Field (which is defined in the DAO library):


Dim fields(2) As Field


The users have specified what names they want to give to those two new fields in the New Table dialog box’s text boxes, so we create the new fields this way:



Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)

Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
...


Now that the new fields are created, we can append them to the actual TableDef object td:


Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)

Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)
...
End Sub


That’s it—we’ve defined two new fields, named them, and appended them to a TableDef object. Next, we’ll add an index to our table to allow the user to sort the data in that object.

DAO: Adding An Index To A TableDef Object
You use an index to sort a table, and you create an index with the DAO CreateIndex method. The CreateIndex method creates an Index object, and you can make one of the fields in a table that table’s index with that Index object’s CreateField method.
Let’s see an example to make this clearer. We’ll create an index for our DAO example, the daocode project (see the first topic in this chapter) named dbindex, which we declare as a form-wide variable:


Dim dbindex As Index


We name the index when we create it; here, we’ll just use the first field that the user has placed in this table as the table’s index so all sort operations will sort using that field. In this example, we name our index by adding the word “index” to the name of that field this way:



Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)

Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)

Set dbindex = td.CreateIndex(TableForm.Text2.Text & "index")
...


Next, we create a new field, indexfield, in the index, using the name of the first field in the table:


Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)

Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)

Set dbindex = td.CreateIndex(TableForm.Text2.Text & "index")
Set indexfield = dbindex.CreateField(TableForm.Text2.Text)
...


Finally, we append indexfield to our Index object, dbindex, and append that object to the TableDef object’s Indexes collection:


Sub CreateTable()
Set td = db.CreateTableDef(TableForm.Text1.Text)

Set fields(0) = td.CreateField(TableForm.Text2.Text, dbText)
Set fields(1) = td.CreateField(TableForm.Text3.Text, dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)

Set dbindex = td.CreateIndex(TableForm.Text2.Text & "index")
Set indexfield = dbindex.CreateField(TableForm.Text2.Text)
dbindex.fields.Append indexfield
td.Indexes.Append dbindex
...
End Sub


And that’s it—we’ve created a new index for our table. In fact, we’ve set up the whole TableDef object td now, so we can create a record set to start working with data, and we’ll do that in the next topic.



Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
863 03
863 ind
863 (2)
859 862
863 06
863 08
863 12
863 865
Rozp w sprawie przepisów techniczno budowlanych dla lotnisk cywilnych Dz U 98 130 859 tekst ost z
863 07
863 05
857 859
863 00
Zasadnicze wymagania dla urządzeń spalających paliwa gazowe 03 91 859
857 859

więcej podobnych podstron