Jump to content

Write to Microsoft Access Database

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Kapper

Kapper

    Newbie

  • Members
  • Pip
  • 1 posts
Hi..
I need some help to save input from user into an Microsoft Access Data base I created?
If the user type his/her name into the textbox, the users name need to be saved in the database under the name tab?

Thanks..

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I can help out with that.

you need to use ADO.NET.

So, the process works like this

You need to create an ADO.NET Connection object, more specifically an OleDBConnection object. This connection object establishes context to that Access database of yours, using a connection string. The syntax is more or less like this:

OleDbConnection connectio = new OleDbConnection("connection string");


Once you have that context established, you need to send instructions to the database provider. And this is done with a combination of that connection object, and a command object.


connection.Open();

OleDbCommand command = new OleDbCommand("INSERT INTO users (name) VALUES (@name)");

command.Parameters.AddWithValue("@name", txtname.text);

int rows_affected = command.ExecuteNonQuery();

command.Dispose();

connection.Dispose();


thats basically it. However this is a really sparse explanation, there are patterns that you want to learn to use to make this more robust and elegant. But hey, you need a starting point.

So to learn how to establish context to specifically an Access File Database, you should check this out.
Access 2007 Connection String Samples - ConnectionStrings.com

this is not intended to be code you cut and paste, instead, read it, try to understand it, and get a conversation going. I'll answer your questions.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users