Finding a Particular Row in a DataSet : DataSet « ADO.net Database « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » ADO.net Database » DataSet 
Finding a Particular Row in a DataSet

<%@ Page Language="C#" ClassName="Default" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {
        SqlConnection  sqlConnection;
        SqlDataAdapter sqlDataAdapter;
        SqlCommand     sqlCommand;
        DataSet       dataSet;
        DataTable      dataTable;
    
    if (IsPostBack) {
      try{
          sqlConnection = new SqlConnection"Integrated Security=yes;Initial Catalog=Northwind;Data Source=(local)" );
        sqlCommand = new SqlCommand"Select * From Customers", sqlConnection );
              
        sqlDataAdapter = new SqlDataAdaptersqlCommand );
        dataSet = new DataSet();
      
        sqlDataAdapter.FilldataSet, "Customers" );
    
        DataColumn [] pkColumn = new DataColumn[1];
        pkColumn[0= dataSet.Tables[0].Columns["CustomerID"];

        dataSet.Tables[0].PrimaryKey = pkColumn;

        DataRow rowFound = dataSet.Tables[0].Rows.Find(customerIdTextBox.Text);
        
        if (rowFound == null)
        {
          msgLabel.Text = "The Customer ID entered was not found.";
        }
        else
        {
          StringBuilder stringBuilder = new StringBuilder("Contact ");

          stringBuilder.Append(rowFound["ContactName"].ToString());
          stringBuilder.Append(", ");
          stringBuilder.Append(rowFound["ContactTitle"].ToString());
          stringBuilder.Append(" at ");
          stringBuilder.Append(rowFound["CompanyName"].ToString());

          msgLabel.Text = stringBuilder.ToString();
        }
      }
      catchException exception )
      {
        msgLabel.Text = exception.ToString();
      }
    }
    }

</script>
<html>
  <head>
    <title>Finding a Particular Row in a DataSet</title>
  </head>
  <body>
    <form id="form1" method="post" runat="server">
      <asp:label id="customerIdLabel" runat="server">Customer ID:</asp:label>
      <asp:textbox id="customerIdTextBox" runat="server"></asp:textbox>
      <asp:button id="findButton" runat="server" Text="Find"></asp:button><br>
      <asp:label id="msgLabel" runat="server" ></asp:label></form>
  </body>
</html>

 
Related examples in the same category
1. Loop through data in Sql Server by DataSet
2. Loop through DataSet
3. Get query result from DataSet
4. Load Table from DataSet
5. Build a DataSet
6. Create DataSet pragmatically
7. Build a DataSet with relationship
8. Output the content of a DataSet as XML
9. Converting XML to DataSet and Vice versa
10. Converting XML to DataSet and Vice versa (VB)
11. Programmatically creating a DataSet object
12. DataSet Serialization and Deserialization using Binary Format
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.