Use SQL IN operations IN ASP. NET

Source: Internet
Author: User

This article will create a DataGrid containing the CheckBox control, which allows you to select multiple columns for detailed browsing. If you have not recovered any way to obtain this function for dynamic SQL statements, you must use the IN operation.
At the end of the article, we wrote an SQL Server user-defined function (UDF), in order to break a string into sub-strings with delimiters. In this article, we can see how such a UDF works. We will create a web form where you can select some records in the DataGrid by selecting the checkbox control. Details of these checked records will appear in another DataGrid in the form. This form is like.
 
The following shows the ASPX used to create a form. Note: How to Use the TemplateColumn and Checkbox controls to add a DataGrid column. We also use the DataKeyField attribute of the DataGrid to tell the object which field recorded in the database will contain the keyword identifier of the first line.
  
<Form id = "Form1" method = "post" runat = "server">
<Asp: DataGrid id = "DataGrid1" runat = "server"
AutoGenerateColumns = "False" DataKeyField = "EmployeeID">
<Columns>
<Asp: TemplateColumn>
<ItemTemplate>
<Asp: CheckBox runat = "server" ID = "EmployeeCheckBox"/>
</ItemTemplate>
</Asp: TemplateColumn>
<Asp: TemplateColumn>
<ItemTemplate>
<% # DataBinder. Eval (Container. DataItem, "LastName") %>,
<% # DataBinder. Eval (Container. DataItem, "FirstName") %>
</ItemTemplate>
</Asp: TemplateColumn>
</Columns>
</Asp: DataGrid>
<Hr>
<Asp: Button id = "Orders" runat = "server" Text = "View Orders"> </asp: Button>
<Hr>
<Asp: DataGrid ID = "DataGrid2" Runat = "server" AutoGenerateColumns = "True"/>
</Form>
When loading and initializing a form, you need to assemble the top DataGrid. The Code uses the Enterprise Library to access the SQL Sever Northwind instance database and runs the "SELECT EmployeeID, FirstName, LastName FROM Employees" statement. The code for loading an event is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.