Get data in database through SqlDataAdapter (C#) : SQLDataAdapter « ADO.net Database « ASP.Net





Get data in database through SqlDataAdapter (C#)

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
   <title>DataSet Example</title>
   <head>
      <script runat="server">
         void Page_Load()
         {
            String ConnStr = "Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=java2suser;Password='password';";
            String SQL = "SELECT ID, FirstName FROM Employee " 
               + "WHERE ID IS NOT NULL";
            SqlDataAdapter TitlesAdpt = new SqlDataAdapter(SQL, ConnStr);
            DataSet Titles = new DataSet();
            // No need to open or close the connection
            //   since the SqlDataAdapter will do this automatically.
            TitlesAdpt.Fill(Titles);
            Output.Text = "<table>";
            foreach (DataRow Title in Titles.Tables[0].Rows)
            {
               Output.Text += "<tr>";
               Output.Text += "<td>" + Title[0] + "</td>";
               Output.Text += "<td>" + String.Format("{0:c}", Title[1]) 
                  + "</td>";
               Output.Text += "</tr>";
            }
            Output.Text += "</table>";
         }
      </script>
   </head>
<body>
   <h1>DataSet Example</h1>
   <asp:label id="Output" runat="server"/>
</body>
</html>
           
       










Related examples in the same category

1.Bind Data from Sql Server (VB.net)
2.Read data from SqlConnection (VB.net)
3.Retrieving SQL Server Data (VB.net)