I have this in a public class:
SqlConnection myConnection = new SqlConnection("Data Source=hermes;database=qcvalues; Integrated Security=SSPI;");
myConnection.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(InitializeQuery(), myConnection);
myReader = myCommand.ExecuteReader();
I need the datasource of a control to get the dataset from myReader.
Unfortunately this is difficult to do because the control is on a form (a separate class). how would I return myReader
dataset into the datasource
property of the control on my form?
You don't. Use a DataAdapter instead:
var ds = new DataSet();
using(var conn = new SqlConnection(connString))
{
conn.Open();
var command = new SqlCommand(InitializeQuery(), conn);
var adapter = new SqlDataAdapter(command);
adapter.Fill(ds);
}
if you can use DataAdapter subclass or use something as:
DataTable myTable = new DataTable();
myTable.Load(myCommand.ExecuteReader());
and then return DataTable to client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With