Net-informations.com
SiteMap  | About    

How to Asp.Net Dataset

A DataSet contains rows, columns,primary keys, constraints, and relations with other DataTable objects. The DataSet is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source.

We can use Dataset in combination with SqlDataAdapter Class . Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter. The SqlDataAdapter object allows us to populate Data Tables in a DataSet.

vb.net
  Dim adapter As New SqlDataAdapter(sql, connection)

adapter.Fill(ds)

C#
  SqlDataAdapter adapter = new SqlDataAdapter(sql,connection );

adapter.Fill(ds);

The following ASP.NET program retrieve publishers name from publisher table using a Dataset.

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
		<br />
		<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
		<br />
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb





net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.