web 2.0

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource - The ObjectDataSource represents a business object that provides data to data-bound controls in multitier Web application architectures.

ShotDev Focus:
- ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Tag Control :


<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

On current project Right Click -> Add New Item

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Add new item DataSet.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Right Click on DataSet Designer -> Add -> TableAdapter

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

TableAdapter Configuration Wizard -> Choose Data Connection or Create New Connection.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Choose Database Source.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Click Next for go to next Step.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Save a ConnectionString.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Enter a SQL Statement or Query.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Choose Method to Generate. and Click Finish to Save

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

TableAdapter From creating.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Drag ObjectDataSource to ASP.NET Web Form. on ObjectDataSource Tasks -> Click Configure Data Source…

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Choose a Business Object.

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

Choose Debine Data Methods (SELECT,UPDATE,INSERT,DELETE).

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

DragĀ  GridView Control to ASP.NET Web Form and Choose Data Source Form ObjectDataSource.

Example Code

Default.aspx


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="myCustomerTableAdapters.customerTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_CustomerID" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CountryCode" Type="String" />
<asp:Parameter Name="Budget" Type="Decimal" />
<asp:Parameter Name="Used" Type="Decimal" />
<asp:Parameter Name="Original_CustomerID" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CountryCode" Type="String" />
<asp:Parameter Name="Budget" Type="Decimal" />
<asp:Parameter Name="Used" Type="Decimal" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CustomerID" DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="CountryCode" HeaderText="CountryCode"
SortExpression="CountryCode" />
<asp:BoundField DataField="Budget" HeaderText="Budget"
SortExpression="Budget" />
<asp:BoundField DataField="Used" HeaderText="Used" SortExpression="Used" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Default.aspx.vb

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="myCustomerTableAdapters.customerTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_CustomerID" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CountryCode" Type="String" />
<asp:Parameter Name="Budget" Type="Decimal" />
<asp:Parameter Name="Used" Type="Decimal" />
<asp:Parameter Name="Original_CustomerID" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CountryCode" Type="String" />
<asp:Parameter Name="Budget" Type="Decimal" />
<asp:Parameter Name="Used" Type="Decimal" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CustomerID" DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="CountryCode" HeaderText="CountryCode"
SortExpression="CountryCode" />
<asp:BoundField DataField="Budget" HeaderText="Budget"
SortExpression="Budget" />
<asp:BoundField DataField="Used" HeaderText="Used" SortExpression="Used" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource

.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

One Response to “ASP.NET(vb.net) & ObjectDataSource - asp:ObjectDataSource”

  1. 2marshall…

Leave a Reply

You must be logged in to post a comment.