connecting and using access to store data from .net
This can be used in either a windows application OR an asp.net file.
NOTICE: if using with asp.net file the access file MUST be placed and refered to in the ROOT directory of IIS.
ok, first make the reference
using System.Data.OleDb;
to open and close connection....
OleDbConnection thisConnection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:/WEB_SERVER/server_user_database.MDB");
thisConnection.Open();
//work here//
thisConnection.Close();
to add data...
OleDbCommand new1 = new OleDbCommand("INSERT INTO tablename (column(s)) values('valueshere')", thisConnection);
new1.ExecuteNonQuery();
to retrieve data...
OleDbDataReader myReader=null;
OleDbCommand test = new OleDbCommand("select * from tablename, thisConnection);
myReader = test.ExecuteReader();
while(myReader.Read())
{Label1.Text=(myReader["columnnamehere"].ToString());};
myReader.Close();
always close connection!!!...
thisConnection.Close();
NOTICE: if using with asp.net file the access file MUST be placed and refered to in the ROOT directory of IIS.
ok, first make the reference
using System.Data.OleDb;
to open and close connection....
OleDbConnection thisConnection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:/WEB_SERVER/server_user_database.MDB");
thisConnection.Open();
//work here//
thisConnection.Close();
to add data...
OleDbCommand new1 = new OleDbCommand("INSERT INTO tablename (column(s)) values('valueshere')", thisConnection);
new1.ExecuteNonQuery();
to retrieve data...
OleDbDataReader myReader=null;
OleDbCommand test = new OleDbCommand("select * from tablename, thisConnection);
myReader = test.ExecuteReader();
while(myReader.Read())
{Label1.Text=(myReader["columnnamehere"].ToString());};
myReader.Close();
always close connection!!!...
thisConnection.Close();
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home