For a multi-condition search page, if each of the five conditions is written, 25 add queries are used, and 10 are 100 add queries.
TableAdapter can publish two methods: suitable for filling in the Fill method of the existing DataSet and returning the Get method of the filled DataTable object. The former is more suitable for Windows clients (DataSet is stored in memory during the lifetime of the Application), while the latter (that is, the Get method) is more suitable for ObjectDataSource.
Create a class file: (function: add the original tableadapter file and add the required class)
Namespace FernandoTableAdapters
{
Public partial class OutRegisterTableAdapter
{
Public virtual Fernando. OutRegisterDataTable GetDataBySearch (string searchSql)
{
This. Adapter. SelectCommand = new System. Data. OleDb. OleDbCommand (searchSql, this. Connection );
Fernando. OutRegisterDataTable dataTable = new Fernando. OutRegisterDataTable ();
This. Adapter. Fill (dataTable );
Return dataTable;
}
}
}
Then, just like the original operation, open the class file and add the method:
[System. ComponentModel. DataObjectMethodAttribute (System. ComponentModel. DataObjectMethodType. Select, false)]
Public Fernando. OutRegisterDataTable GetOutRegisterBySearch (string searchSql)
{
Return Adapter. GetDataBySearch (searchSql );
}
The last page is displayed:
<Asp: ObjectDataSource ID = "OutRegisterDataSource" runat = "server" SelectMethod = "GetOutRegisterBySearch"
TypeName = "OutRegister" OldValuesParameterFormatString = "original _ {0}" DeleteMethod = "DeleteOutRegister"
UpdateMethod = "LogOutOutRegister">
<SelectParameters>
<Asp: Parameter Name = "searchSql" Type = "String" DefaultValue = "SELECT * from OutRegister"/>
</SelectParameters>
<DeleteParameters>
<Asp: Parameter Name = "outRegisterID" Type = "Int32"/>
</DeleteParameters>
<UpdateParameters>
<Asp: Parameter Name = "outRegisterID" Type = "Int32"/>
</UpdateParameters>
</Asp: ObjectDataSource>
Enter the cs file:
Protected void Button3_Click (object sender, EventArgs e)
{
String searchSql = "SELECT * from OutRegister where OutRegisterID = 2 ";
OutRegisterDataSource. SelectParameters ["searchSql"]. DefaultValue = searchSql;
}