2010-01-25 4 views

답변

2

디자이너에서 TableAdapter의 ConnectionModifier 속성을 설정할 수 있으며 기본적으로 Internal이므로 동일한 프로젝트/어셈블리에서 사용할 수 있으므로 공용으로 변경하고 필요한 모든 곳에서 사용할 수 있습니다. 또는 더 나은 aproach는 TableAdapter에 이름/네임 스페이스에 기반을 둔 부분 클래스를 생성하고 같은 테이블 어댑터 내에 로직을 캡슐화합니다

// 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 
     } 
    } 
} 
0
typedTableAdapter ta = new myNameSpace.myDataSet.myDataSetTableAdapters.typedTableAdapter; 

SqlClient.SqlCommand com = new SqlClient.SqlCommand("my query"); 
com.Connection = ta.Connection;