G
gaffar
Sir,
I used this below code for the ms access database and tables creation but
if the table contains 20 fields and i would like to store 10 fields only
then i am getting this error.
error meesage:
the field 'new_custdetails.salutation ' cannot contain a null value because
the required property for this field is set to true. enter a value in this
filed
how to solve this problem. please help me. how to set the required property.
CODE:
Dim cat As Catalog = New Catalog
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")
cat = Nothing
MsgBox("Database succesfully created")
End If
'creating tables in the database
'
' This code adds a single-field Primary key
'
Dim Cn As ADODB.Connection
Dim Cat2 As ADOX.Catalog
Dim objTable1, objtable2 As ADOX.Table
Cn = New ADODB.Connection
Cat2 = New ADOX.Catalog
objTable1 = New ADOX.Table
objtable2 = New ADOX.Table
'Open the connection
Try
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")
'"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\sample\gaffar.mdb"
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Open the Catalog
Cat2.ActiveConnection = Cn
'Create the table
objTable1.Name = "new_custdetails"
objtable2.Name = "Test_Table2"
'Create and Append a new field to the "Test_Table" Columns Collection
objTable1.Columns.Append("company", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("contact", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("salutation", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("title", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("dept", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phone", DataTypeEnum.adInteger)
objTable1.Columns.Append("phext1", DataTypeEnum.adInteger)
objTable1.Columns.Append("fax", DataTypeEnum.adInteger)
objTable1.Columns.Append("mobile", DataTypeEnum.adInteger)
objTable1.Columns.Append("altphone", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phext2", DataTypeEnum.adInteger)
objTable1.Columns.Append("status", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("dob", DataTypeEnum.adDate)
objTable1.Columns.Append("address1", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("address2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("city", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("state", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("zip", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("country", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("reffered", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("website", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("email", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("lastresult", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("contact2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("title2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phone2", DataTypeEnum.adInteger)
objTable1.Columns.Append("phext", DataTypeEnum.adInteger)
objTable1.Columns.Append("create_date", DataTypeEnum.adDate)
objTable1.Columns.Append("pub_pri", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("rec_creator", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("rec_mgr", DataTypeEnum.adVarWChar)
'Create and Append a new key. Note that we are merely passing
'the "PimaryKey_Field" column as the source of the primary key. This
'new Key will be Appended to the Keys Collection of "Test_Table"
''objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, "company")
', "new_custdetails")
'objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyUnique, "contact") ',
"new_custdetails")
'objTable1.Keys.Append("PrimaryKey3", KeyTypeEnum.adKeyPrimary, "dept",
"new_custdetails")
'Append the newly created table to the Tables Collection
Cat2.Tables.Append(objTable1)
I used this below code for the ms access database and tables creation but
if the table contains 20 fields and i would like to store 10 fields only
then i am getting this error.
error meesage:
the field 'new_custdetails.salutation ' cannot contain a null value because
the required property for this field is set to true. enter a value in this
filed
how to solve this problem. please help me. how to set the required property.
CODE:
Dim cat As Catalog = New Catalog
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")
cat = Nothing
MsgBox("Database succesfully created")
End If
'creating tables in the database
'
' This code adds a single-field Primary key
'
Dim Cn As ADODB.Connection
Dim Cat2 As ADOX.Catalog
Dim objTable1, objtable2 As ADOX.Table
Cn = New ADODB.Connection
Cat2 = New ADOX.Catalog
objTable1 = New ADOX.Table
objtable2 = New ADOX.Table
'Open the connection
Try
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")
'"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\sample\gaffar.mdb"
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Open the Catalog
Cat2.ActiveConnection = Cn
'Create the table
objTable1.Name = "new_custdetails"
objtable2.Name = "Test_Table2"
'Create and Append a new field to the "Test_Table" Columns Collection
objTable1.Columns.Append("company", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("contact", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("salutation", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("title", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("dept", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phone", DataTypeEnum.adInteger)
objTable1.Columns.Append("phext1", DataTypeEnum.adInteger)
objTable1.Columns.Append("fax", DataTypeEnum.adInteger)
objTable1.Columns.Append("mobile", DataTypeEnum.adInteger)
objTable1.Columns.Append("altphone", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phext2", DataTypeEnum.adInteger)
objTable1.Columns.Append("status", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("dob", DataTypeEnum.adDate)
objTable1.Columns.Append("address1", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("address2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("city", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("state", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("zip", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("country", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("reffered", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("website", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("email", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("lastresult", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("contact2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("title2", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("phone2", DataTypeEnum.adInteger)
objTable1.Columns.Append("phext", DataTypeEnum.adInteger)
objTable1.Columns.Append("create_date", DataTypeEnum.adDate)
objTable1.Columns.Append("pub_pri", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("rec_creator", DataTypeEnum.adVarWChar)
objTable1.Columns.Append("rec_mgr", DataTypeEnum.adVarWChar)
'Create and Append a new key. Note that we are merely passing
'the "PimaryKey_Field" column as the source of the primary key. This
'new Key will be Appended to the Keys Collection of "Test_Table"
''objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, "company")
', "new_custdetails")
'objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyUnique, "contact") ',
"new_custdetails")
'objTable1.Keys.Append("PrimaryKey3", KeyTypeEnum.adKeyPrimary, "dept",
"new_custdetails")
'Append the newly created table to the Tables Collection
Cat2.Tables.Append(objTable1)