0% found this document useful (0 votes)
34 views

20BSC Worksheet 3.1

This document outlines a practical lab assignment to implement server-side applications using web controls by creating a SQL database table, connecting a Windows form to the database, and writing C# code to insert data into the table from text boxes on the form. The student is tasked with creating a table, connecting the form to the database, writing code to insert data into the table, and displaying the output. The learning outcomes are basic database connection concepts, SQL queries, and data grid view display.

Uploaded by

Saurabh Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

20BSC Worksheet 3.1

This document outlines a practical lab assignment to implement server-side applications using web controls by creating a SQL database table, connecting a Windows form to the database, and writing C# code to insert data into the table from text boxes on the form. The student is tasked with creating a table, connecting the form to the database, writing code to insert data into the table, and displaying the output. The learning outcomes are basic database connection concepts, SQL queries, and data grid view display.

Uploaded by

Saurabh Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICAL NUMBER: 3.

Student Name: Vishesh Chaudhary UID: 20BSC1024


Branch: BSC Section/Group: A
Semester: 6 Date of Performance: 5/MAY/2023
Subject: Web Application Dev LAB Subject Code: 20SCP-354

1.AIM:

Implement server-side applications using web controls.


2. Task to be done:

1. Connection – To work with the data in a database, the first obvious step is the
connection. The connection to a database normally consists of the below-mentioned
parameters.
2. Database name or Data Source – The first important parameter is the database name.
Each connection can only work with one database at a time.
3. Credentials – The next important aspect is the ‘username’ and ‘password’. This is used
to establish a connection to the database.
4. Optional parameters – You can specify optional parameters on how .net should handle
the connection to the database. For example, one can specify a parameter for how long
the connection should stay active.
5. Selecting data from the database – Once the connection is established, data is fetched
from the database. ASP.Net has the ability to execute ‘sql’ select command against the
database. The ‘sql’ statement can be used to fetch data from a specific table in the
database.
6. Inserting data into the database – ASP.Net is used to insert records into the database.
Values for each row that needs to be inserted in the database are specified in ASP.Net.
7. Updating data into the database – ASP.Net can also be used to update existing records
into the database. New values can be specified in ASP.Net for each row that needs to be
updated into the database.
4. Tools Used:
1. Button
2. Picture Box
3. Label
4. Textbox
5. ComboBox

1|Page
5. Steps for experiment/practical:

SQL Query
CREATE TABLE [dbo].[Table]
(
[Emp_Name] NCHAR(10) NULL PRIMARY KEY,
[Emp_id] NCHAR(10) NULL,
[Emp_email] NVARCHAR(50) NULL,
[Emp_Cabin] NCHAR(10) NULL,
[Emp_shift] NCHAR(10) NULL
)

1. Create a SQL Database

2|Page
2. Create a Table in the dataset using the sql query.

3. Update the table to the database

3|Page
4. Windows form for user interaction

5. Write the necessary C# code to establish a connection between the


form and the SQL Database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

emp_namespace vishesh_chaudhary_work3._1

4|Page
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection("Data Source=(localdb)\\MSSqlLocalDB;Initial
Catalog=vishesh3;Integrated Security=True");
SqlCommand comm = new SqlCommand();
try
{

conn.Open();

comm.Connection = conn;

string emp_name = textBox1.Text;


string emp_id = textBox3.Text;
string emp_email = textBox4.Text;
string emp_cabin = textBox5.Text;
string emp_shift = textBox6.Text;

comm.CommandText = "INSERT INTO [dbo].[Table]


VALUES(@emp_name,@emp_id,@emp_email , @emp_cabin, @emp_shift)";

comm.Parameters.AddWithValue("@emp_name", emp_name);
comm.Parameters.AddWithValue("@emp_id", emp_id);
comm.Parameters.AddWithValue("@emp_email", emp_email);
comm.Parameters.AddWithValue("@emp_cabin", emp_cabin);
comm.Parameters.AddWithValue("@emp_shift", emp_shift);

comm.ExecuteNonQuery();
MessageBox.Show("Your Account has been Created");
}
catch (Exception)

5|Page
{
MessageBox.Show("Unfortunately your account has not been created");
throw;
}
finally
{
conn.Close();
}
}
}
}
6. Output:

6|Page
EMPLOYEE DATABASE TABLE

4. Learning Outcomes:
1.Basic Concepts of Database connection
2. SQL Server connection and Query
3. Data Grid view data display.
4. Database and Server connection

7|Page
Evaluation Grid:

Sr. Parameters Marks Obtained Maximum Marks


No.
1. Demonstration and 5
Performance
2. Worksheet 10
3. Post Lab Quiz 5

8|Page

You might also like