creating tables using ADO.NET

  • Thread starter Thread starter headware
  • Start date Start date
H

headware

I understand that you can't create .mdb files using ADO.NET. That's
not a problem for me. What I really want to be able to do is create
all the tables in an empty database based on a text file that
specifies the schema. I'm fine with the text file containing a bunch
of SQL CREATE statements but I'm also fine using ADO.NET to create
DataTables and DataColumns. The problem with using ADO.NET is that I
can't figure out how to set certain Access field properties such as
"Allow Zero Length" for text fields or "Format" for Date/Time fields.
Can this be done without using ADOX?

Thanks,
Dave
 
Hi Dave
Yes you can do that with ado there are so many types that you can specify,
including time, o data columns when declaring them
for example
mycolumn = new DataColumn("salary" , Type.GetType("System.Decimal"));
and if you want to read more types at
http://search.microsoft.com/search/results.aspx?View=msdn&st=a&qu=Type+Membe
rs&c=0&s=1
also you can use some properties of the DataColumn object as a work around
for having or not having empty sting values .
for example
mycolumn.AllowDBNull = true;
then you can use the columns you build into building tables
for example
mytable.Columns.Add(mycolumn);
once you have the table , start adding rows to it , you can do it also
throw code
for example,
DataRow myrow = mytable.NewRow();
myrow["salary"]= 11.1;
you can do it many different ways actually ; for example,
mytable.Rows.Add(myrow);
mytable.Rows.Add(new object[]{12.2});
mytable.Rows.Add(new object[]{14.7});

hope this helps ,
 
On 17 Feb 2004 21:19:23 -0800, (e-mail address removed) (headware) wrote:

¤ I understand that you can't create .mdb files using ADO.NET. That's
¤ not a problem for me. What I really want to be able to do is create
¤ all the tables in an empty database based on a text file that
¤ specifies the schema. I'm fine with the text file containing a bunch
¤ of SQL CREATE statements but I'm also fine using ADO.NET to create
¤ DataTables and DataColumns. The problem with using ADO.NET is that I
¤ can't figure out how to set certain Access field properties such as
¤ "Allow Zero Length" for text fields or "Format" for Date/Time fields.
¤ Can this be done without using ADOX?

Some properties are specific to Access and cannot be modified via SQL DLL. Format is one them. If I
remember correctly, Allow Zero Length is ignored by Access SQL DDL.

DAO will handle any property and ADOX, all but a few exceptions.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Right but there's no "Format" property for dates. How do most people
use scripts to create tables? Do they use SQL satements? I couldn't
find the proper SQL statements for Access that would do what I want
(specify "format" and "allowing zero length" strings etc.). All that
I'm trying to do here is maintain version control over the database. I
can store the .mdb itself Visual Source Safe, but since it's a binary
file, but I can't compare new versions to older versions to see
differences in the schema. As a workaround, I thought we'd use scripts
to create the database and keep those scripts in Source Safe, but I
can't seem to find a way to create a fully functional Access database
using scripts. How do people normally do this?

Thanks,
Dave
 
Back
Top