Topics covered in this video;
-Code Behind
-Populating Dropdown List
-using's (ie system.data, system.configuration)
-\ (escape sequences)
-SQLConnection
-SQL/Data Adapters
-DataSet/DataTable
-Session Variable
-Strings
-Creating a button
-Variables being passed over
-Debugging for drop down list
-PostBack
This example uses the Case Study - Medicare Database
It duplicates code from the lecture Getting Started with Database Tools in Visual Studio
http://online1.daytonastate.edu/player2.php?id=bc7f621451b4f5df308a8e098112185d
using System;
System.Data.SqlClient.SqlConnection sConn = new System.Data.SqlClient.SqlConnection(cStr);
System.Data.SqlClient.SqlDataAdapter sAdpt = new System.Data.SqlClient.SqlDataAdapter("SELECT DISTINCT(State) FROM RawData", sConn);
sAdpt.Fill(ds);
ddlSelectState.DataSource = ds; |
Most important section is System.Data to have access to Data Objects.
page load event is triggered
Only perform this if not a post back
This the connection string for the database, the @ symbol means to use it as a literal string.
Create a new SqlConnection object using the connection string.
Create a SQL Adapter to run a SQL command and fill DataSet.
Create a DataSet to hold the results of the query.
Put the Query results in the DataSet.
Set the DataSource for the drop down list to the DataSet and specify parameters. Bind the drop down to the dataset
If the Done button is pressed, get the selected value, store it in the Session and pass control of program to new page. |