Create a new DataAdapter for every query?

Hello,

I got another question: When doing a query, you do something like:
SqlDataAdapter adapter = new SqlDataAdapter("SELECT customers.* FROM customers WHERE...", connection);

Now I have another query which should replace the first query, but runs on exactly the same table-scheme. Should I create a new SqlDataAdapter for this or can I re-use the adapter I created before somehow?
[404 byte] By [martho] at [2007-11-20 7:03:28]
# 1 Re: Create a new DataAdapter for every query?
You can reuse it
adapter.SelectCommand.CommandText="SELECT ..."
aniskhan at 2007-11-10 3:30:07 >
# 2 Re: Create a new DataAdapter for every query?
Thanks a lot, this works fine!

But I got a 2nd problem with this: I need to transfer a DataRow from the DataTable to another, so I use something like:
DataRow row = dataTable.Rows[0];

But when sending another query with
adapter.SelectCommand.CommandText = sSql;
the ItemsArray in row gets invalid:
(+ ItemArray 'this.row.ItemArray' threw an exception of type 'System.Data.RowNotInTableException' object[] {System.Data.RowNotInTableException}

How can I avoid this?
martho at 2007-11-10 3:31:09 >
# 3 Re: Create a new DataAdapter for every query?
You need to copy thge data (usually) out of the DataRow object into some structure, then create a new DataRow object to add into the new table. DataRow's can NOT be moved between DataTable's as they are owned by them.
TheCPUWizard at 2007-11-10 3:32:08 >
# 4 Re: Create a new DataAdapter for every query?
like this:

'our original datatable
Me.TestTableAdapter.Fill(Me.TestDataSet.Test)

'our new one
Dim x As New TestDataSet.TestDataTable

'make a new row
Dim y As TestDataSet.TestRow = x.NewTestRow()

'copy the values
y.ItemArray = Me.TestDataSet.Test.Rows(0).ItemArray

'add the new row to the new table
x.AddTestRow(y)
cjard at 2007-11-10 3:33:02 >