Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Does testing a field's Nullability with "adFldIsNullable" work for you?


Message #1 by "Alex Barnard" <dumbardos@b...> on Thu, 7 Mar 2002 04:28:11
Anyone reading this please try the code below. 



All you have to do is copy and paste the code (between ========) into a 

blank text file anywhere on you PWS or Webserver and call 

it "nulltest.asp" 



Open a browser and load the test ASP file "nulltest.asp"

e.g. http://127.0.0.1/nulltest.asp



The code will create the following database "C:\adoNullTest.mdb" with two 

fields "NonNullableField" and "NullableField"



I get the following result displayed in browser window.......



Field :NonNullableField

Attrib:234

Nullable :True

---------------------------------------------------------

Field :NullableField

Attrib:234

Nullable :True



Which is total nonsense as if you open the database in Access you will see 

"NonNullableField" attribute "required" = Yes

"NullableField" attribute "required" = No

but they both have the same Attributes



"NonNullableField" should have attribute of 202 and "Nullable :"=False



Please test this code and post your results by replying to this thread. 

Quote your Platform and MDAC and Jet versions. Also see MS explanation for 

this error using older versions of JET and MDAC.

http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q185823&



I have MDAC 2.52 installed with Jet 4.0 drivers, running on WIN98SE using 

PWS4. According to MS it should work. It did with MDAC 2.1.



THE CODE

====================================================

<%

Option Explicit

const DB_PATH="C:\adoNullTest.mdb"

Const adOpenStatic = 3

Const adLockReadOnly = 1

Const adFldIsNullable = &H00000020



Dim conn,dbString,rs,FSYS,newdb,fld



'CHECK EXISTING EXAMPLE DB EXISTS

set FSYS=createobject("Scripting.FilesystemObject")

if FSYS.fileexists(DB_PATH) then

	'DELETE TEST DB

	FSYS.deletefile DB_PATH

end if	



'CREATE TEST DATABASE

dbString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&DB_PATH&";"

Set newdb = Server.CreateObject("ADOX.Catalog") 

newdb.create dbString

set newdb=nothing



'THE REAL STUFF STARTS HERE......................



'OPEN DB CONNECTION OBJECT

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open dbString

'CREATE TABLE+FIELDS 1)NONNULLABLE 2)NULLABLE

conn.Execute "CREATE TABLE AdoNullableTest " & _

                "(NonNullableField TEXT NOT NULL, NullableField TEXT)"



' Open a recordset on the new table - I use a Query rather then a table 

(adCmdTable) as I need to use SQL commands.

set rs = Server.CreateObject("ADODB.Recordset") 

rs.Open "SELECT * FROM AdoNullableTest", conn, adOpenStatic, adLockReadOnly

'LOOP FOR EACH FIELD IN DB

for each fld in rs.Fields

	'SHOW NAME-VALUE-NULLABILITY

	response.write "<b>Field</b> :" & fld.Name & "<BR>"

	response.write "<b>Attrib</b>:" & fld.Attributes & "<BR>"

	response.write "<b>Nullable</b> :"&((fld.Attributes and 

adFldIsNullable)=adFldIsNullable)&"<hr>"

Next

'CLEAR UP

rs.Close

conn.close

set fSYS=nothing

set rs=nothing

set conn=nothing

%>

========================================================================

  Return to Index