20BSC Worksheet 3.1
20BSC Worksheet 3.1
1.AIM:
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
)
2|Page
2. Create a Table in the dataset using the sql query.
3|Page
4. Windows form for user interaction
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();
}
conn.Open();
comm.Connection = conn;
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:
8|Page