-2

How can I create a ms access database in C#? I have created an application using which I can drain some specific information about hardware and software now I want to create a database and write those information to an Access database file!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

1 Answers1

0

I have never used c# to create a database, but this maybe helpful: https://support.microsoft.com/nl-nl/kb/149558

I have used an existing Access database in combination with c#.

The connectionprovider below may vary on the Access version. Here are some connectionstrings: https://www.connectionstrings.com/access/

//Making the connection
string databaseLocation = "location";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databaseLocation);

//Opening the connection
con.Open();

//Making a command
OleDbCommand odc = new OleDbCommand("query",con);

//Execute a select query
OleDbDataReader reader = odc.ExecuteReader();

//Example of retrieving data from select query
while(reader.Read())
{
   string result = reader.getString(0);
}

//Execute different query (examples: insert into, update, delete)
odc.ExecuteNonQuery();

//Closing the connection
con.Close();

I hope it helps!

Ron van Asseldonk
  • 1,275
  • 2
  • 11
  • 18