Simple Database Connection Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have some basic code and the corresponding resources needed that
will enable me to connect to an Access Database in .net compact frmwrk using
C#. I need to learn how to create a recordset and do some reading, updating
and appending. I can't seem to find any straight forward examples. It's all
blah, blah, blah. I would appreciate any code that I can build on.

Thank you.
 
Thu. Aug. 26, 2004 10:10 PM PT

MyDataBase = your Access .MDB file, give a full path of your file location,
check the syntax
MyTable = your table in Access database.
If you want ODBC connection string Let me know.
I hope this will solve your probs.

Good Luck.
[C#]
// OLE DB Driver string for MS Access database

SqlConnection con = new SqlConnection(("Data
Source="c:\\temp\\MyDataBase.mdb";Provider=\"Microsoft.Jet.OLEDB.4.0\";Jet
OLEDB:Engine Type=5;");
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "Select from MyTable";
cmd.ExecuteQuery();
or
cmd.ExecuteReader();
con.Close()
 
Hi Poewood,

The connection strings can be found here:

http://www.connectionstrings.com/

You can use OleDbDataAdapter to fill data from the database into a dataset.
You can use the same dataadapter to write data back to the database.

Maybe one of these are what you are looking for:

http://www.codeproject.com/cs/database/csharpaccessdb.asp
http://www.c-sharpcenter.com/Tutorial/DatabaseConn_01.htm
http://c-sharpcenter.com/Tutorial/Database2.htm
http://c-sharpcenter.com/Tutorial/DB_part3.htm
http://www.c-sharpcenter.com/Tutorial/DB_part4.htm
 
Poewood said:
Does anyone have some basic code and the corresponding resources needed
that
will enable me to connect to an Access Database in .net compact frmwrk
using
C#. I need to learn how to create a recordset and do some reading,
updating
and appending. I can't seem to find any straight forward examples. It's
all
blah, blah, blah. I would appreciate any code that I can build on.

There's no Access database driver for the Compact Framework. I'd suggest SQL
Server CE.

Tim
 
But isn't the SQL Server CE database really a "pocket Access Dbase"? How do
I convert an Access Database to a SQL Server CE databse?
 
Back
Top