473,774 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I create an MDB with ADO.NET

I have been used to using DAO in the past, and then converted to ADO.

Now I am having to use VB.Net(2000) and ADO.NET and am experiencing
difficulties with the creation and population of an mdb.

I can create the MDB and am doing so by creating a module as shown below.
I have added the ADO reference: Microsoft ADO Ext. 2.7 for DDL and
Security in the references section of the project.

This creates the MDB but as soon as it tries to create the table I get the
error message:
An unhandled exception of type
'System.Runtime .InteropService s.COMException' occurred in
InventoryManage r.exe
Additional information: Type is invalid.

I am at a loss as how to proceed as my help file is alas not very helpful on
creating MDB's as all help references appear to assume everyone is using a
sql server all the time.

Many thanks for feedback.

Terry

CODE SAMPLE STARTS HERE

Imports ADOX
Module Module1
Dim m_MDBFile As String = Application.Sta rtupPath & "\NEWDATA.m db"
Dim cat As Catalog = New Catalog()

Public Sub CreateDATAMDB()
Kill(m_MDBFile)
'Dim cat As Catalog = New Catalog()
cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
"Data Source=" & m_MDBFile & ";" & _
"Jet OLEDB:Engine Type=5")

createTbl1()

cat = Nothing
End Sub

Private Sub createTbl1()
Dim tblFRED As New ADOX.Table()
With tblFRED
.Name = "FRED"
.Columns.Append ("NAME", DataTypeEnum.ad Char)
.Columns.Append ("AGE", DataTypeEnum.ad Integer)
.Columns.Append ("ADDRESS", DataTypeEnum.ad Char)
.Columns.Append ("SPENT", DataTypeEnum.ad Double)
End With
cat.Tables.Appe nd(tblFRED)
End Sub


Jul 21 '05 #1
3 8291
In C#, try

string mdbFileName = Application.Sta rtupPath + @"\NEWDATA.mdb" ;

// Delete mdb file if already exists
if (System.IO.File .Exists(mdbFile Name))
{
System.IO.File. Delete(mdbFileN ame);
}

Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

if (objClassType != null)
{
object obj = Activator.Creat eInstance(objCl assType);
// Create mdb file
obj.GetType().I nvokeMember("Cr eate",
System.Reflecti on.BindingFlags .InvokeMethod, null, obj, new object[]{
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + mdbFileName + ";" });

if (System.IO.File .Exists(mdbFile Name))
{
using (OleDbConnectio n connection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" + mdbFileName
+ ";Persist Security Info=False"))
{
try
{
connection.Open ();

// Create the table
using (OleDbCommand command = new OleDbCommand("C REATE TABLE
FRED (NAME nvarchar(30) NOT NULL, AGE int, ADDRESS nvarchar(80), SPENT
float)", connection))
{
command.Execute NonQuery();
}

// Create a primary key
using (OleDbCommand command = new OleDbCommand("A LTER TABLE FRED
ADD CONSTRAINT FREDindex0 PRIMARY KEY (NAME)", connection))
{
command.Execute NonQuery();
}
}
catch (OleDbException exception)
{
}
finally
{

if (connection.Sta te == System.Data.Con nectionState.Op en)
{
connection.Clos e();
}
}
}
}
}

All the Best,
Phil.

"anon" wrote:
I have been used to using DAO in the past, and then converted to ADO.

Now I am having to use VB.Net(2000) and ADO.NET and am experiencing
difficulties with the creation and population of an mdb.

I can create the MDB and am doing so by creating a module as shown below.
I have added the ADO reference: Microsoft ADO Ext. 2.7 for DDL and
Security in the references section of the project.

This creates the MDB but as soon as it tries to create the table I get the
error message:
An unhandled exception of type
'System.Runtime .InteropService s.COMException' occurred in
InventoryManage r.exe
Additional information: Type is invalid.

I am at a loss as how to proceed as my help file is alas not very helpful on
creating MDB's as all help references appear to assume everyone is using a
sql server all the time.

Many thanks for feedback.

Terry

CODE SAMPLE STARTS HERE

Imports ADOX
Module Module1
Dim m_MDBFile As String = Application.Sta rtupPath & "\NEWDATA.m db"
Dim cat As Catalog = New Catalog()

Public Sub CreateDATAMDB()
Kill(m_MDBFile)
'Dim cat As Catalog = New Catalog()
cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
"Data Source=" & m_MDBFile & ";" & _
"Jet OLEDB:Engine Type=5")

createTbl1()

cat = Nothing
End Sub

Private Sub createTbl1()
Dim tblFRED As New ADOX.Table()
With tblFRED
.Name = "FRED"
.Columns.Append ("NAME", DataTypeEnum.ad Char)
.Columns.Append ("AGE", DataTypeEnum.ad Integer)
.Columns.Append ("ADDRESS", DataTypeEnum.ad Char)
.Columns.Append ("SPENT", DataTypeEnum.ad Double)
End With
cat.Tables.Appe nd(tblFRED)
End Sub


Jul 21 '05 #2
On Sat, 5 Mar 2005 17:02:15 -0000, "anon" <ng*@tdrd.frees erve.co.uk> wrote:

¤ I have been used to using DAO in the past, and then converted to ADO.
¤
¤ Now I am having to use VB.Net(2000) and ADO.NET and am experiencing
¤ difficulties with the creation and population of an mdb.
¤
¤ I can create the MDB and am doing so by creating a module as shown below.
¤ I have added the ADO reference: Microsoft ADO Ext. 2.7 for DDL and
¤ Security in the references section of the project.
¤
¤ This creates the MDB but as soon as it tries to create the table I get the
¤ error message:
¤ An unhandled exception of type
¤ 'System.Runtime .InteropService s.COMException' occurred in
¤ InventoryManage r.exe
¤ Additional information: Type is invalid.
¤
¤ I am at a loss as how to proceed as my help file is alas not very helpful on
¤ creating MDB's as all help references appear to assume everyone is using a
¤ sql server all the time.
¤
¤ Many thanks for feedback.
¤
¤ Terry
¤
¤ CODE SAMPLE STARTS HERE
¤
¤ Imports ADOX
¤ Module Module1
¤ Dim m_MDBFile As String = Application.Sta rtupPath & "\NEWDATA.m db"
¤ Dim cat As Catalog = New Catalog()
¤
¤ Public Sub CreateDATAMDB()
¤ Kill(m_MDBFile)
¤ 'Dim cat As Catalog = New Catalog()
¤ cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
¤ "Data Source=" & m_MDBFile & ";" & _
¤ "Jet OLEDB:Engine Type=5")
¤
¤ createTbl1()
¤
¤ cat = Nothing
¤ End Sub
¤
¤ Private Sub createTbl1()
¤ Dim tblFRED As New ADOX.Table()
¤ With tblFRED
¤ .Name = "FRED"
¤ .Columns.Append ("NAME", DataTypeEnum.ad Char)
¤ .Columns.Append ("AGE", DataTypeEnum.ad Integer)
¤ .Columns.Append ("ADDRESS", DataTypeEnum.ad Char)
¤ .Columns.Append ("SPENT", DataTypeEnum.ad Double)
¤ End With
¤ cat.Tables.Appe nd(tblFRED)
¤ End Sub
Use adVarWChar instead of adChar.
Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Jul 21 '05 #3
Thanks for the feedback - I am programming in Vb, however it did help sort
out the problem for me.
"Phil Williams" <Ph**********@d iscussions.micr osoft.com> wrote in message
news:FE******** *************** ***********@mic rosoft.com...
In C#, try

string mdbFileName = Application.Sta rtupPath + @"\NEWDATA.mdb" ;

// Delete mdb file if already exists
if (System.IO.File .Exists(mdbFile Name))
{
System.IO.File. Delete(mdbFileN ame);
}

Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

if (objClassType != null)
{
object obj = Activator.Creat eInstance(objCl assType);
// Create mdb file
obj.GetType().I nvokeMember("Cr eate",
System.Reflecti on.BindingFlags .InvokeMethod, null, obj, new object[]{
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + mdbFileName + ";" });

if (System.IO.File .Exists(mdbFile Name))
{
using (OleDbConnectio n connection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" + mdbFileName + ";Persist Security Info=False"))
{
try
{
connection.Open ();

// Create the table
using (OleDbCommand command = new OleDbCommand("C REATE TABLE
FRED (NAME nvarchar(30) NOT NULL, AGE int, ADDRESS nvarchar(80), SPENT
float)", connection))
{
command.Execute NonQuery();
}

// Create a primary key
using (OleDbCommand command = new OleDbCommand("A LTER TABLE FRED ADD CONSTRAINT FREDindex0 PRIMARY KEY (NAME)", connection))
{
command.Execute NonQuery();
}
}
catch (OleDbException exception)
{
}
finally
{

if (connection.Sta te == System.Data.Con nectionState.Op en)
{
connection.Clos e();
}
}
}
}
}

All the Best,
Phil.

"anon" wrote:
I have been used to using DAO in the past, and then converted to ADO.

Now I am having to use VB.Net(2000) and ADO.NET and am experiencing
difficulties with the creation and population of an mdb.

I can create the MDB and am doing so by creating a module as shown below. I have added the ADO reference: Microsoft ADO Ext. 2.7 for DDL and
Security in the references section of the project.

This creates the MDB but as soon as it tries to create the table I get the error message:
An unhandled exception of type
'System.Runtime .InteropService s.COMException' occurred in
InventoryManage r.exe
Additional information: Type is invalid.

I am at a loss as how to proceed as my help file is alas not very helpful on creating MDB's as all help references appear to assume everyone is using a sql server all the time.

Many thanks for feedback.

Terry

CODE SAMPLE STARTS HERE

Imports ADOX
Module Module1
Dim m_MDBFile As String = Application.Sta rtupPath & "\NEWDATA.m db"
Dim cat As Catalog = New Catalog()

Public Sub CreateDATAMDB()
Kill(m_MDBFile)
'Dim cat As Catalog = New Catalog()
cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
"Data Source=" & m_MDBFile & ";" & _
"Jet OLEDB:Engine Type=5")

createTbl1()

cat = Nothing
End Sub

Private Sub createTbl1()
Dim tblFRED As New ADOX.Table()
With tblFRED
.Name = "FRED"
.Columns.Append ("NAME", DataTypeEnum.ad Char)
.Columns.Append ("AGE", DataTypeEnum.ad Integer)
.Columns.Append ("ADDRESS", DataTypeEnum.ad Char)
.Columns.Append ("SPENT", DataTypeEnum.ad Double)
End With
cat.Tables.Appe nd(tblFRED)
End Sub


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8869
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
4
4418
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create shortcut to my program/utility (2) Entry in Windows' Start --> Program Menu. Actually in my VB.Net solution I have two projects (1) MYPROGRAM (2) MYPROGRAM_INSTALLER. MYPROGRAM is a "Windows Application". MYPROGRAM_INSTALLER is a "SetUp Wizard"...
10
8822
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung other things, can create views based on existing tables and a table of column name equivalents. If I accidently introduce a column name equivalent that is the same as another column, I end up with a CREATE VIEW SQL statement that is in error, if...
9
8325
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the records in the database. Is it possible to create a SQL Server database using vb.net? I know I can use vb.net and ADOX to create a Access database. But I can't create SQL database using vb.net.
37
3311
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html PEP: XXX Title: The create statement
18
2720
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html In this post, I'm especially soliciting review of Carl Banks's point (now discussed under Open Issues) which asks if it would be better to have the create statement translated into:
5
4871
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The Exchange System Manager is running on the web server and Exchange SP2 has been installed. The IIS site is configured with Basic Authentication and users are prompted to enter their Active Directory credentials when connecting to the site.
8
20369
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1: Start with original thumbnails & two empty sub directories STEP 2: Create smaller versions of the originals for one sub directory STEP 3: Create thumbnail version of the originals the other sub directory STEP 4: Create an index.html pointing to the...
2
22621
by: masri999 | last post by:
I have a requirement in SQL 2005 in Development database 1. Schema dbo owns all objects (tables,views,SPs,UDFs etc) . 2. Only DBA's ( who are database owners ) can create, alter tables . Developer's should not create or alter tables . 3. Developers can create/alter Stored Procedure/User Defined functions in dbo schema and can execute SP/UDF. 4. Developers should have SELECT,INSERT,DELETE,UPDATE on tables ( tables in dbo schema
4
3751
by: JohnnyDeep | last post by:
I am trying to create a store proc that contain a create index with the cluster option and I receive DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0623N A clustering index already exists on table "PGIR.TF_RRCE". LINE NUMBER=35. SQLSTATE=55012
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.