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!
Asked
Active
Viewed 801 times
1 Answers
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
-
Do I need any sort of reference to bring OLEDconnection !? – Sir MJM Jul 01 '15 at 09:30
-
thanks pal! but i found the an easier answer in the duplicate of my question! Thanks again! – Sir MJM Jul 01 '15 at 09:35
-
Yes, I think you'll need a reference. Right klik on it, then resolve and it should display the reference you need. No problem. Glad I could help! – Ron van Asseldonk Jul 01 '15 at 09:46