Data Access question

N

Nurchi BECHED

Hello, everyone

I am a newbie in the data access in .NET environment.

I was trying to show something from an MDB file in the form,
but nothing seems to work.

In Visual FoxPro it would take me a couple lines of code to
do anything in the DBASE database or table.
A little more with other formats..., but still in C#, I have
no idea what I am doing or should be doing to display data
in the datagrid.

I don't want to use design-time controls (other than datagrid
itself), if possible.

There is an Access database (orders.mdb)
and a table inside (orders)

I need a simple example of how to display, change contents,
add/delete rows, etc.

I've been to www.codeproject.com and didn't find anything really
useful (for dummies like me, lol) there.

Thanks in advance.

--
Regards,
Nurchi BECHED

P.S.
C makes it easy to shoot yourself in the foot;
C++ makes it harder, but when you do,
it blows away your whole leg."
--Bjarne Stroustrup
 
W

W.G. Ryan eMVP

OleDbConnection cn = new OleDbConnection("ConnectionStringHere");
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Orders", cn);
DataTable dt = new DataTable():
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
DataGrid.DataSource = dt;

The "easiest" way is to use a CommandBuilder - but they are very limited...
You'd just add a commandbuilder here and pass in the dataadapter as the
argument. Then just call da.Update(dt);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top