Connectivity in Timetable for students in c#

Contents:-

1)    Introduction

2)    Background

3)    Select Data query

4)    Update Data query

5)    Insert Data Query

6)    Working

 

Introduction:

Timetable is the basic part of any institution. All the tasks are accomplished according to available timetable. It is very useful thing which prevent the system from clashing .And every member of the system goes through this scenario.

 

Background:

Basically timetable was programmed according to the needs of teacher and students i.e.at what time one is available. Connectivity was basically developed to connect the database of school timetable. In which timetable was made according to the available timings of teachers and updating and removing factor is possible, sql connection is made for further updating.

 

Working:

First of all in form 1 SqlConnection was developed to use the stored data. It is very essential because stored data can be utilized at any time .Big storage can be available at any time.

public partial class Form1 : Form

connection to database:

{

SqlConnection connection = new SqlConnection(@”Data Source=Home-pc\SQLEXPRESS;Initial Catalog=Time Table DB;Integrated Security=True”);

DataSet dataset = new DataSet();

SqlDataAdapter DataAdap = new SqlDataAdapter();

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

 

}

 

 

private void button1_Click(object sender, EventArgs e)

Insert Data into Teacher table:-

try

{

String ID = IDTextBox.Text;

int id = Convert.ToInt16(ID);

DataAdap.InsertCommand = new SqlCommand(“insert into Teacher (Teacher_ID,Teacher_FirstName,Teacher_LastName,Teacher_Phone,Teacher_Email)values(@TeacherID,@TeacherFirstName,@TeacherLastName,@TeacherPhone,@TeacherEmail)”, connection);

DataAdap.InsertCommand.Parameters.Add(“@TeacherID”, SqlDbType.Int).Value = id;

DataAdap.InsertCommand.Parameters.Add(“@TeacherFirstName”, SqlDbType.NVarChar, 50).Value = FirstNametextBox.Text;

DataAdap.InsertCommand.Parameters.Add(“@TeacherLastName”, SqlDbType.NVarChar, 50).Value = LastTextBox.Text;

DataAdap.InsertCommand.Parameters.Add(“@TeacherPhone”, SqlDbType.NVarChar, 50).Value = PhonetextBox.Text;

DataAdap.InsertCommand.Parameters.Add(“@TeacherEmail”, SqlDbType.NVarChar, 50).Value = EmailtextBox.Text;

DataAdap.InsertCommand.Parameters.Add(“@course”, SqlDbType.Int).Value = textBox1.Text;

connection.Open();

DataAdap.InsertCommand.ExecuteNonQuery();

connection.Close();

 

}

 

For Exception Case:-

catch

{

MessageBox.Show(“Error”);

}

Description:-

If there is an exception then data will be inserting through finally code.

finally

{

DataAdap.InsertCommand.Dispose();

}

SqlCommand Command = new SqlCommand(“DisplayTeacherRecord”, connection);

Command.CommandType = CommandType.StoredProcedure;

Command.Parameters.Add(“@TeacherID”, SqlDbType.Int).Value =id;

Command.Parameters.Add(“@TeacherFirstName”, SqlDbType.NVarChar, 50).Value = FirstNametextBox.Text;

Command.Parameters.Add(“@TeacherLastName”, SqlDbType.NVarChar, 50).Value = LastTextBox.Text;

Command.Parameters.Add(“@TeacherPhone”, SqlDbType.NVarChar, 50).Value = PhonetextBox.Text;

Command.Parameters.Add(“@TeacherEmail”, SqlDbType.NVarChar, 50).Value = EmailtextBox.Text;

MessageBox.Show(“Enter Successfully”);

}

 

private void textBox1_TextChanged(object sender, EventArgs e)

{

 

}

 

private void button1_Click_1(object sender, EventArgs e)

{

function();

}

 

 

For updating Data:-

The data which is present after running will show data and it will show updating data after clearing previous data via grid view.

 

private void button2_Click(object sender, EventArgs e)

{

dataGridView1.ClearSelection ();

String ID = IDTextBox.Text;

int id = Convert.ToInt16(ID);

DataAdap.UpdateCommand = new SqlCommand (“Update Teacher SET Teacher_FirstName=@TeacherFirst,Teacher_LastName=@TeacherLast,Teacher_Phone=@TeacherPhone,Teacher_Email=@TeacherEmail,Course_ID=@course where Teacher_ID=@TeacherID”, connection);

DataAdap.UpdateCommand.Parameters.Add(“@TeacherID”, SqlDbType.Int).Value = id;

DataAdap.UpdateCommand.Parameters.Add(“@TeacherFirst”, SqlDbType.NVarChar, 50).Value = FirstNametextBox.Text;

DataAdap.UpdateCommand.Parameters.Add(“@TeacherLast”, SqlDbType.NVarChar, 50).Value = LastTextBox.Text;

DataAdap.UpdateCommand.Parameters.Add(“@TeacherPhone”, SqlDbType.NVarChar, 50).Value = PhonetextBox.Text;

DataAdap.UpdateCommand.Parameters.Add(“@TeacherEmail”, SqlDbType.NVarChar, 50).Value = EmailtextBox.Text;

DataAdap.UpdateCommand.Parameters.Add(“@course”, SqlDbType.Int).Value = textBox1.Text;

connection.Open();

DataAdap.UpdateCommand.ExecuteNonQuery();

connection.Close();

function();

DataAdap.UpdateCommand.Dispose();

 

}

 

Select data query:

 

public void function()

{

DataAdap.SelectCommand = new SqlCommand(“select * from Teacher”, connection);

DataAdap.Fill(dataset);

dataGridView1.DataSource = dataset.Tables[0];

connection.Open();

DataAdap.SelectCommand.ExecuteNonQuery();

connection.Close();

 

DataAdap.SelectCommand.Dispose();

}}