User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Dec 2007
Posts: 3
Reputation: Mukoyonzo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Mukoyonzo Mukoyonzo is offline Offline
Newbie Poster

Troubleshooting Databinding problem

  #1  
Dec 13th, 2007
Hi, I have developed my program with three windows forms and would like to bind to the Access database to read data from particular tables, How do I bind?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 762
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 4
Solved Threads: 59
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: Databinding problem

  #2  
Dec 14th, 2007
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/
Reply With Quote  
Join Date: Oct 2007
Posts: 92
Reputation: Jugortha is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
Jugortha Jugortha is offline Offline
Junior Poster in Training

Re: Databinding problem

  #3  
Dec 14th, 2007
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) { }
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 3:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC