The following code is adapted from Microsoft's code here. It is therefore obviously correct.
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = GetConnectionString();
ReturnIdentity(connectionString);
}
private static void ReturnIdentity(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Create a SqlDataAdapter based on a SELECT query.
SqlDataAdapter adapter = new SqlDataAdapter("SELECT CategoryID, CategoryName FROM dbo.Categories", connection);
// Create a DataTable and fill it.
DataTable categories = new DataTable();
adapter.Fill(categories);
}
}
static private string GetConnectionString()
{
return "Your Connection String";
}
}
Despite this obviously correct code containing no DataSet that I can find, the documentation for the Fill method called with adapter.Fill(categories) above makes repeated mentions of DataSets, as if they're somehow relevant/mandatory to using the Fill(DataTable) method of the SqlDataAdapter class.
This gives me my question: Where in the above code does any DataSet appear? I can't think of any reading of the documentation for SqlDataAdapter.Fill(DataTable) that doesn't make it sound like you absolutely need one.
The SqlDataAdapter class has multiple overloaded versions of Fill that accepts different arguments, including DataSet and DataTable instances. See the documentation for a complete list.