This Question Is Answered:
 Why do we use in sqldataadpter and sqlcommand and sqldatareader and datatable?
 23 Jun 2007 12:12
 Flag
  In .net there are many different ways to do database works. I use only these three... Dataconnection, DataAdapter and Datatable.

DataConnection is the connectivity to the database, like the path of a file.

DataAdapter handles the connection and QueryString both. It can execute the query and fill a table with data. with adapters you don't have to read row by row anymore.

DataTable is like a 2D array that can handle a set of columns and rows. It can be directly assigned to the DataSource of a DataGridView (in a flash, you will see the query results, no loops and row by row).

Create an instance of DataConection giving the connection string.

And an instance of DataAdapter giving the QueryString and that DataConnection (as parameters).

And make a DataTable, use fill method of DataAdapter to fill data to the table.

Like this...

ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|MyDataBase.mdb";
QStr = "SELECT * FROM MyTable";

DCon = new OleDbConnection(ConnStr);
DCon.Open();

DataTable DTbl = new DataTable();
DAdp = new OleDbDataAdapter(QStr, DCon);
DAdp.Fill(DTbl);

DataGridView1.DataSource=DTbl;

// and DataGridView1 will show all the contents of "MyTable"

SQL Data also works as this, just replace all "OleDb" with "Sql"
Unrated

1 ratings
by   vishva
  08 Aug 2007 15:24
 Flag
 Excellent answer.
by   Boris   25 Sep 2007 21:48    
Comment
  
Comment
  

1000 words left

    


 You may consider using SQLDataReader if you just need to quickly read some information from the database. It is much more efficient for this purpose than the DataAdapter/DataTable.
Unrated

0 ratings
by   Boris
  25 Sep 2007 21:48
 Flag

1000 words left

    


Blurtit Tools:  Email to a Friend    Bookmark this page
What Is The Main
Difference Between The
Database And The Database
Management System...
What's The Difference Of
C++ And Java Script?
What Is Data Flow
Diagram?
What is rmi? Explain in
short.
How To Write Order Of
Events In Microsoft Word?
How can I copy/move my
database (SQL/Oracle)
from one PC to another?
I Don't Have Any Idea
About SQl Database?Are
There Any Sites (videos)
Available So...
In databases, If a query
is taking a lot of time
to execute, what could be
the reason...
Are there any sites which
teach you how to
create,delete and update
a database?
What Is The Main
Difference Between Oracle
And Sql Server?
My Blurtit
My Profile
My Questions
My Answers
Blurtit Features
Ask a Question
Answer a Question
Search an Answer
Categories
Tools
Link to Blurtit
Add Blurtit to Firefox
Search Engine
See Your Site Here
Link to Blurtit
RSS
Blurtit.com
About Us
Terms & Conditions
Privacy Policy
Contact Us
Advertise With Us
Help
International
 Chinese Site
 Japanese Site
To continue you need to be registered with us first.

I am already a Blurter, and need to login
I am not a Blurter yet, but would like to register