Re: Create Access Database in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Mark Rae" <mark@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23$6IG4lPFHA.4028@xxxxxxxxxxxxxxxxxxxxxxx

> Brian,

Actually, on reflection, a much more elegant solution might be to include a
blank Access database as an Embedded Resource in your app, as it will be a
mere 64k in length. Then, when you need to create a new DB, just write it
out to the file system wherever you need it, naming it as required.

1) Using Access, create a blank database called something like template.mdb
(or whatever).

2) Create a new C# WinForms project called Brian (or whatever).

3) Drag the newly created DB into your C# project, setting its Build Action
property to Embedded Resource.

4) Use the following code to extract the blank DB out of your assembly and
onto the hard drive:

try
{
byte[] abytResource;
System.Reflection.Assembly objAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

objStream = objAssembly.GetManifestResourceStream("Brian.template.mdb");
abytResource = new Byte[objStream.Length];
objStream.Read(abytResource, 0, (int)objStream.Length);
objFileStream = new FileStream(<path> + "\\" + <newName.mdb>,
FileMode.Create);
objFileStream.Write(abytResource, 0, (int)objStream.Length);
objFileStream.Close();

}
catch (Exception)
{
throw;
}
finally
{
if (objFileStream != null)
{
objFileStream.Close();
objFileStream = null;
}
if (objStream != null)
{
objStream = null;
}
}


.



Relevant Pages

  • ForBrian, Ms access and Delphi
    ... Hi Brian, would you please provide me a sample code for a module which has a ... TAdoConnection and how it connects to an ms access database and a simple SQL ...
    (borland.public.delphi.database.ado)
  • Re: Other User Connected to ADO MSAccess Table?
    ... Brian, thanks for your support. ... not in an ADOConnection Win32 application? ... When you run it AdoDataset1 should be populated with one record for each ... logged on to your Access database. ...
    (borland.public.delphi.database.ado)
  • Re: ADO faster than ADO.net ?
    ... Brian ... "Cor Ligthert" wrote: ... > 'Test inserting 30000 records into an Access database table using ADO.net ... Prev by Date: ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO faster than ADO.net ?
    ... Brian ... "Cor Ligthert" wrote: ... > 'Test inserting 30000 records into an Access database table using ADO.net ... Prev by Date: ...
    (microsoft.public.dotnet.framework.adonet)