•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 430,109 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,168 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1046 | Replies: 2
![]() |
Use ADO.NET!
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
•
•
Join Date: Oct 2007
Posts: 92
Reputation:
Rep Power: 1
Solved Threads: 8
You can't ignore ADO.NET or avoid it when building applications that consume data in both contexts I mean Windows forms and web forms
ADO.NET offers two Modes to deal with data
The connected mode witch means that we are connected directly with the database
I give u a piece of code that illustrate this case:
suppose that we will connect to a data base "C:\Test.mdb" in order to consume data from a table within it called "Table"
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
MessageBox.Show(myReader[0].ToString());
}
}
finally
{
myReader.Close();
}
myConnection.Close();
This DataReader is used to only read forward data directly from the data base
The disconnected mode is the most used by the programmers it consists on loading data to an xml files format named DataSets cached in the computed memory and the connection then is released you deal then with cached data, once you finished you can update your data base from the cached data in the datasets and those code lines help you to perform the deal
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
try
{
myAdapter.Fill(myDataSet);
}
catch (Exception caught) { }
myConnection.Close();
After entering changes on myDataSet during the a given session an you want to save modification to your database use this framgement of code
try
{
myAdapter.Update(myDataSet);
}
catch (Exception caught) { }
ADO.NET offers two Modes to deal with data
The connected mode witch means that we are connected directly with the database
I give u a piece of code that illustrate this case:
suppose that we will connect to a data base "C:\Test.mdb" in order to consume data from a table within it called "Table"
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
MessageBox.Show(myReader[0].ToString());
}
}
finally
{
myReader.Close();
}
myConnection.Close();
This DataReader is used to only read forward data directly from the data base
The disconnected mode is the most used by the programmers it consists on loading data to an xml files format named DataSets cached in the computed memory and the connection then is released you deal then with cached data, once you finished you can update your data base from the cached data in the datasets and those code lines help you to perform the deal
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbConnection myConnection = new OleDbConnection(/*This is the connection string*/@"Provider= Microsoft.JET.OLEDB.4.0; Data Source=C:\Test.mdb");
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("Select * From Table", myConnection);
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
try
{
myAdapter.Fill(myDataSet);
}
catch (Exception caught) { }
myConnection.Close();
After entering changes on myDataSet during the a given session an you want to save modification to your database use this framgement of code
try
{
myAdapter.Update(myDataSet);
}
catch (Exception caught) { }
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Need help with ms access and vb.net (VB.NET)
- add new record to database (VB.NET)
- combobox control (VB.NET)
- Combo box selection problem (VB.NET)
- How to add rows from dataset to datagridview (C#)
- How to Populate listbox2 (ASP.NET)
- ASP.NET 2.0, Parent/Child Data Control? (ASP.NET)
- Paging in dataGrid (ASP.NET)
- Updating DB using SqlDataAdapter (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Regarding images in button column of datagridview
- Next Thread: DataAdapter problem with MS-Access


Linear Mode