210 likes | 380 Views
Tutorial -3. ADO.NET. Things to do in Tutorial 4. Registering the server and connection to our database Creating a table Sample Application which demonstrates, populating data from database and inserting data into database Populating data into ListBox, GridView, Tables.
E N D
Tutorial -3 ADO.NET
Things to do in Tutorial 4 • Registering the server and connection to our database • Creating a table • Sample Application which demonstrates, populating data from database and inserting data into database • Populating data into ListBox, GridView, Tables
Getting started with “SQL Server “ - 1 • Open Microsoft SQL Server -> Enterprise Manager • Select SQL Server Group, right click on it, and select “New SQL Server Registration”
SQL Server Registration - 1 • Click “Next”, and then select the SQL Server with name as “KC-ISSRV-SQL1.KC.UMKC.EDU”, click on Add button and then Next button
SQL Server Registration - 2 • Use default selected options and click on “Next”
SQL Server Registration - 3 • Click on “Finish” and then “Close”. Your server is now registered
Running the SQL Server • Click on KCSQL5, and then click on “Yes” option from the below shown prompt. Select “Databases” and search for “cs551-1” database
Creating a Table • To create a table, right click on Tables, and select New Table as below, and design your table as follows:
Sample Application • We will create a simple application where we can retrieve data from a table, and display in different controls and also insert data into a table. • The basic example will be of using ListBox, getting data into listbox, selecting some data form the listbox to another listbox and then inserting selected data into database • Code samples to populate data from database into different controls such as “GridView” and “Dynamic Tables” are also included.
Create a new “Web Site”, and design your web form as shown below. Controls used in the web form are ListBox, GridView, Table, Literal, Buttons
Adding data to listbox from database • Double click on the web form, and add the code in the next slide under Page_Load function. • Also add the namespaces using System.Data.SqlClient and using System.Data.OleDb. • string connectString = "User ID=cs551fs06-group1; PWD=$Free$pace;Initial Catalog= cs551fs06-group1;Data Source=kc-issrv-sql1.kc.umkc.edu";
Double Click on “Get data into list” and add the below code. Also add the namespaces using System.Data.SqlClient; and using System.Data.OleDb; Use the ones given in the code file
Double Click on “>>” button and add the below code. Double Click on “<<” button and add the below code.
Double Click on “Get data into GridView” button and add the below code.
Double Click on “Get data into Table” button and add the below code.