Hello,

Can you please help me I want to know the functions used to save a data in access database, I have the code to save in a file but is it possible to save in a database in C language.

Reegards,
Noora

Dani AI

Generated

As asked for "functions" to save into an Access database and pointed out the API-vs-implementing-an-engine tradeoff: the practical reality is that Access files (.mdb/.accdb) are controlled by Microsofts Jet/ACE engine. That means plain file I/O (fopen/fwrite) will not produce a valid Access file. Either call the Access engine/driver that understands the format, or build a full database engine yourself (the latter is not realistic for a small task).

Two practical approaches, depending on constraints:

  • Keep Access as the target: use Microsoft's Access Database Engine (ACE) via its provider/driver and call it from C. On Windows this is usually done through COM (ADO/OLE DB): initialize COM, create a connection object, open the database with a connection string, then execute SQL INSERT/UPDATE statements. This preserves all Access features but requires the ACE component to be installed and attention to 32/64-bit mismatches and file locking semantics.

  • Drop the Access file requirement and use an embedded C library: SQLite is a single-file, public-domain C library with a very small API that is easy to embed, distribute, and call from plain C. It is ideal when "only C" is required and the database format can be changed. Example usage (minimal):

#include <stdio.h>
#include <sqlite3.h>

int main(void) {
    sqlite3 *db = NULL;
    if (sqlite3_open("mydata.db", &db) != SQLITE_OK) return 1;

    sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY, name TEXT);", 0, 0, 0);

    sqlite3_stmt *stmt = NULL;
    sqlite3_prepare_v2(db, "INSERT INTO people(name) VALUES(?);", -1, &stmt, 0);
    sqlite3_bind_text(stmt, 1, "Noora", -1, SQLITE_STATIC);
    sqlite3_step(stmt);
    sqlite3_finalize(stmt);

    sqlite3_close(db);
    return 0;
}

Troubleshooting and notes: if Access is mandatory, ensure the correct ACE driver is installed and that the process bitness matches the driver (32 vs 64 bit). Expect locking and concurrency limits with Access; for multi-user write-heavy apps consider a server DB. If switching away from Access, export/import via CSV or let Access link to an external backend. For the SQLite API and downloads, see SQLite.

Recommended Answers

All 3 Replies

>I want to know the functions used to save a data in access database
Usually ODBC is used to accomplish this, which can connect to numerous database types using the same API, and it's even been ported to multiple platforms.

Thank you joeprogrammer, but I want a simple code in C, I need oly C language in my software..

>Thank you joeprogrammer, but I want a simple code in C
That's an oximoron.

>I need oly C language in my software..
Well, either you use an API like I suggested previously, or you write it all from scratch, which is unthinkable if all you need is a little database I/O.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.