HOW TO USE SQL DATA SOURCES BY SAHEEN

HOW TO USE SQL DATA SOURCES BY SAHEEN KHAN PRESENTATION ID #22

OUTLINE • What is a SQL data source control and how to create it. • How to define connection and save it in web. config file. • How to configure Select statement. • How to create a Where clause • How to use custom statements and stored procedures.

WHAT IS A SQL DATA SOURCE CONTROL AND HOW TO CREATE IT • A Sql. Data. Source control provides the information an application needs to connect to a database and retrieve the data needed by an application. It can also be used to insert, update and delete and data • To create a SQL data source control, drag the control item from the data group of the Toolbox to a form and then use Configure Data Source command in its smart tag menu to start the Configure Data Source Wizard. • You can also create a SQL data source using the choose data source command in the smart tag menu of bindable control.

DIALOG BOX OF THE DATASOURCE CONFIGUARATION WIZARD


HOW TO DEFINE A CONNECTION • The configure data source dialog box asks you to identify connection for the database you want to use. If you have previously created a connection for the database, you can select it from drop-down list. • To create a new connection, click the new connection button to display the add connection dialog box. Then enter the name of the database server in the server name text box.

• For SQL server express, you can use localhostsqlexpress as the server name. • After you enter the server name, select the authentication mode you want to use. • Then select the database you want to connect to from the dropdown box or enter a database name. • To be sure that the connection is configured properly, you can click the test connection button.


HOW TO SAVE THE CONNECTION STRING IN THE WEB. CONFIG FILE • ASP. NET applications can store connection strings in the web. config file. • If you choose to save the connection string in the web. config file, the connection string attribute of data source control will include a special code that retrieves connection string from web. config file otherwise it will specify the actual connection string. • It is recommended to save the connection in web. config file. Then if the location of the database changes, you can change the connection string in web. config file rather than in each data source that uses the connection.


THE DIALOG BOX FOR SAVING THE CONNECTION STRING IN WEB. CONFIG FILE

HOW TO CONFIGURE THE SELECT STATEMENT • To configure the select statement you choose whether you want to use custom SQL statement or specify the columns from the table or view in the database. • You can click the ORDER BY button to specify how the records should be stored. • You can click the WHERE button to specify the selection criteria.

THE DIALOG BOX FOR DEFINING THE SELECT STATEMENT

HOW TO CREATE A WHERE CLAUSE • The add WHERE clause dialog box lets you specify a where clause for select statement. • To create a condition, you select the column you want to compare, the operator you want to use for the comparison and the source of the data that you want to use for the comparison. • Then you must click Add to add the condition to the list of where clause condition.

THE ADD WHERE CLAUSE DIALOG BOX

THE WHERE CLAUSE SECTION AFTER A CONDITION HAS BEEN ADDED

HOW TO ENTER CUSTOM STATEMENTS AND SELECT STORED PROCEDURES • To use custom statements with SQL data source, select the SQL statement option and then enter the statement into text box. • You can enter select, update, insert, and delete statements by selecting the appropriate tab. • To use stored procedures, select stored procedure option and then select stored procedure you want to use from the dropdown list.

THE DIALOG FOR ENTERING A CUSTOM SELECT STATEMENT

THANK YOU

QUERIES ?
- Slides: 20