web 2.0

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

ASP.NET(vb.net) & SqlDataSource - asp:SqlDataSource The SqlDataSource Represents an SQL database  to data-bound controls. To connect to a database, you must set the ConnectionString property to a valid connection string. The SqlDataSource can support any SQL relational database that can be connected to using an ADO.NET provider, such as the SqlClient, OleDb, Odbc, or OracleClient.

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

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

Drag SqlDataSource control to ASP.NET Web Form. On SqlDataSource Tasks ->Coose Data Source.

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

You can select an existing Connection. Or create new New Connection

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

Select data source or click “Change” to choose a different data source and/or provider…. Click Change…

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

Select Microsoft SQL Server and Click On…

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

Input properties Server name : , Log on to the server , Connect to a database. -> OK

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

Click Next go to next Step.

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

Save an Connectionstring name.

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

Configure the Select Statement.

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

Test Query and Click Finish

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

Drag Gridview control to ASP.NET Web Form and Choose Data Source from SqlDataSource.

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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT * FROM [customer]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CustomerID" DataSourceID="SqlDataSource1">
<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

Partial Class _Default
Inherits System.Web.UI.Page

End Class

Screenshot

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

Download this script.

Download
.
.
Other related articles
ASP.NET(vb.net) SqlDataSource & DataSource
ASP.NET(vb.net) SqlDataSource & Command
ASP.NET(vb.net) SqlDataSource & DataBind
ASP.NET(vb.net) SqlDataSource & GridView RowCommand
ASP.NET(vb.net) SqlDataSource & Visual Studio 2005,2008,2010

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

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

  1. 1crossbow…

Leave a Reply

You must be logged in to post a comment.