Custom Search

Monday, May 5, 2008

SqlDataSource Overview

The SqlDataSource control enables you to quickly and easily represent a SQL database in a web page. In many cases, you can take advantage of the SqlDataSource control to write a database-driven web page without writing a single line of code.You use the SqlDataSource control to represent a connection and set of commands that can be executed against a SQL database. You can use the SqlDataSource control when working with Microsoft SQL Server, Microsoft SQL Server Express, Microsoft Access, Oracle, DB2, MySQL, or just about any other SQL relational database ever created by man.

How to creating Database Connection
By default, the SqlDataSource control is configured to connect to Microsoft SQL Server version 7.0 or higher. The default provider used by the SqlDataSource control is the ADO.NET provider for Microsoft SQL Server.
Example :
< %@ Page Language="VB" %>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
< xmlns="http://www.w3.org/1999/xhtml">
< id="Head1" runat="server">
<>Show Example Connection
< /head>
<>
< id="form1" runat="server">
<>

< id="grdTeacher" datasourceid="srcTeacher" runat="server">

< id="srcTeacher" selectcommand="SELECT * FROM Teacher" connectionstring="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|MyData.mdf; Integrated Security=True;User Instance=True" runat="server">

< /div>
< /form>

< /body>
< /html>

This connection string connects to an instance of SQL Server Express located on the local machine and a database file named MyData.mdf. The connection string uses Integrated Security (a Trusted Connection) to connect to the local database.

No comments:

Free Traffic

 Join My Community at MyBloglog! Blog Flux Directory 

Web Developement Blogs - BlogCatalog Blog Directory web development blog  Internet Blogs - Blog Top Sites 

Blog Directory 

Click Here for Free Traffic!

Link2Communion.com