Iterating Through A DataSet : DataSet « ADO.net Database « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. 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
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 Tutorial » ADO.net Database » DataSet 
18. 27. 3. Iterating Through A DataSet
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    void Page_Load(object sender, EventArgs e)
    {
        string ConnectionString = Convert.ToString(ConfigurationSettings.AppSettings["MSDEConnectString"]);
        string CommandText = "SELECT AuthorName, AuthorCity, AuthorContact_Email, AuthorWebsite FROM Author";
        SqlConnection myConnection = new SqlConnection(ConnectionString);
        SqlCommand myCommand = new SqlCommand(CommandText, myConnection);

       SqlDataAdapter myAdapter = new SqlDataAdapter();

       myAdapter.SelectCommand = myCommand;

       DataSet myDataSet = new DataSet();

       try
       {
          myConnection.Open();

          myAdapter.Fill(myDataSet, "Author");
       catch (Exception ex) {
          throw (ex);
       finally
       {
          myConnection.Close();
       }

       for (int i=0; i<=myDataSet.Tables["Author"].Rows.Count-1; i++)
       {
          Author p = new Author();
          p.Name = myDataSet.Tables["Author"].Rows[i]["AuthorName"].ToString();
          p.City = myDataSet.Tables["Author"].Rows[i]["AuthorCity"].ToString();
          p.Email = myDataSet.Tables["Author"].Rows[i]["AuthorContact_Email"].ToString();
          p.Website = myDataSet.Tables["Author"].Rows[i]["AuthorWebsite"].ToString();

          Label1.Text += p.ToString();

       }
    }


    public class Author
    {
        public string Name;
        public string City;
        public string Email;
        public string Website;

        public Author()
        {}

        public string ToString()
        {
            string description = "";
            description = "Name : " this.Name + "<br />";
            description += "City : " this.City + "<br />";
            description += "Contact : <a href=mailto:" this.Email + ">" this.Email + "</a><br/>";
            description += "Homesite : <a href='" this.Website + "'>" this.Website + "</a><br/><br/>";

            return description;
        }
    }

</script>
<html>
<body>
    <asp:Label id="Label1" runat="server"></asp:Label>
</body>
</html>


File: DataSet

<configuration>
    <appSettings>
      <add key="MSDEConnectString"
           value="server=(local)\YourDatabase;database=Books;uid=YourID;pwd=letmein;" />
    
    </appSettings>
</configuration>
18. 27. DataSet
18. 27. 1. The DataSet object represents an in-memory database.
18. 27. 2. Fill a DataSet
18. 27. 3. Iterating Through A DataSet
18. 27. 4. Fill DataSet with SqlDataAdapter
18. 27. 5. Use OleDbDataAdapter to fill DataSet
18. 27. 6. Iterating Through A DataSet from MySQL database
18. 27. 7. List Binding To A DataSet
18. 27. 8. Pulling Single Values From Dataset Bounded Lists
18. 27. 9. Create DataSet by your own
18. 27. 10. Serialization capabilities of DataSet
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.