I want to execute a custom command against a typed dataset I created using the dataset designer. For this I need to get a reference to the underlying connection, right? How to go about this? In which autogenerated file can I find the connection?
+2
A:
You can set the ConnectionModifier property of the TableAdapter in the designer, is defaulted to Internal, so you can use it in the same project/assembly, change it to Public and use it everywhere you need it. Or a better aproach will be create a partial class based in your TableAdapter name/namespace and encapsulate the logic within the same table adapter:
// if DataSet name is Sales and Table name is Order
namespace SalesTableAdapters // use full namespace here
{
public partial class OrderTableAdapter
{
public void CustomCommand()
{
// here you can use the property this.Connection
// and execute your command
}
}
}
Alex LE
2010-01-25 19:32:14
A:
typedTableAdapter ta = new myNameSpace.myDataSet.myDataSetTableAdapters.typedTableAdapter;
SqlClient.SqlCommand com = new SqlClient.SqlCommand("my query");
com.Connection = ta.Connection;
Joel Etherton
2010-01-25 19:39:20