Problem solve Get help with specific problems with your technologies, process and projects.

How do you create a recordsource using ADO.NET?

How do you create a recordsource using ADO.NET, like you would create a recordsource in VB6 using SQL statements?
If by recordsource you mean the ADO RecordSet, it doesn't exist in ADO.NET. It has been replaced by the far more powerful DataSet. This object represents the data in a source-independent manner, meaning that it will have exactly the same form whether you load it from an XML file, a database or programatically. In order to connect to a database, you use what are called Data Providers, which are implementations of a common interface for a specific database server product. For example, to connect to SQL Server, you use the System.Data.SqlClient namespace, which contains the data provider for it. For OleDb-compliant products, you can use the System.Data.OleDb namespace, likewise.

The good thing is that both implement a common set of classes and methods, allowing your code to be almost identical in both cases, but at the same time allowing each provider to be as efficient as it can at connecting to its specific backend.

The code to fill a DataSet from a SQL statement is straightforward:

SqlDataAdapter ad = new SqlDataAdapter("your SQL query", "your SQLServer
DataSet data = new DataSet();

There are also connection, command and transaction classes, for example, to deal directly with each entity.

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.