SqlDataAdapter from DataSet

How can I get SqlDataAdapter object associated with DataSet?
[66 byte] By [laqula] at [2007-12-16]
# 1
The following code is from MSDN:
I marked the essential line.

public DataSet SelectSqlSrvRows(DataSet dataset,string connection,string query)
{
SqlConnection conn = new SqlConnection(connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}

Marinus

MarinusHolkema at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
I meant that i have a DataSet object and I want to find SqlDataAdapter which generate that DataSet. Something like that:


findAdapter(dataset).Update(dataset.getChanges());


I want to write function findAdapter().
laqula at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 3

The DataSet object is an independant object and by design it does not hold any reference to how it was populated and which object populated. Hence the DataSet does not store information stating which DataAdapter filled it.

It appears to be the same whether filled by a DataAdapter, manually or be reading an XML file.

Hence you might have to store this information in some other collection like a hashtable to map the data adapter with the dataset.

Regards,
Saurabh Nandu
www.MasterCSharp.com
www.AksTech.com

SaurabhNandu at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
In addition to the advice you have already received, it may be worth considering that a dataset might contain multiple tables, which may have been filled by different adapters, so there is not necessarily any one-to-one relationship between a dataset and an adapter. -- Brendan Reynolds wrote in message news:293d7af0-515c-4d2b-ae6a-1fd2b25e055b@discussions.microsoft.com... >I meant that i have a DataSet object and I want to find SqlDataAdapter
> which generate that DataSet. Something like that: >
> [code language="c#"]
> findAdapter(dataset).Update(dataset.getChanges());
> [/code] >
> I want to write function findAdapter(). >
>
MVPUser at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
Good idea.
I have only one table in each DataSet in this application.
laqula at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...