Programming in C# with ADO.Net is much easier than it sounds. Microsoft has made it simpler for anyone to connect. ADO.NET has the ADOData class and if you are using a SQL Server Database you can use SQLDataSet classed for betrer speed and performance.
The first thing you need to do is add the following code to the top of the code form.
using System.Data;
The next thing you need to do is to add a ADO connection resource and an ADO Command resource. You can do this two ways. The first way is from the form.cs(design) open up the toolbox click on the Data components and drag and drop an adoConnection and adoDataSetCommand objects into the form.
The following code will be added to your code form.
private System.Data.ADO.ADODataSetCommand adoDataSetCommand1;
private System.Data.ADO.ADOConnection adoConnection1;
Next you need to make a connection to the database using the adoConnection and th adoDataSetCommand objects. The connection and command string will look like this:
string sConn = "server=localhost;uid=sa;pwd=;database=northwind";
string sCommand ="Select FirstName, LastName FROM Employees";
You then need to connect to the database. This is is done by calling a new ADODataSetCommand object using the command and connection string as the parameters.
ADODataSetCommand DSCmd = new ADODataSetCommand(sCommand, sConn);
So far the ADO.NET has look a lot like the ADO we have come to love and adore. Once we have made the database connection and have queried the Database we are ready for something new. The DataSet Object. The DataSet object. The DataSet Object is more than just an expanded RecordSet. With the DataSet Object you connect to a copy of a database table(s) or even an entire database. Also you are able to read and write to a XML files.
By calling FillDataSet() of the ADODataSetCommand you are able to load a DataSet with data from a database.
Join the conversation! Your thoughts help the community grow.