You are on page 1of 3

using System;

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

namespace WindowsApplication12
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void toolStripMenuItem1_Click(object sender, EventArgs


e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.; Initial Catalog
=seercadd; Integrated Security=true";
con.Open();
}

private void button1_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into seercadd
values(@STUDENT_NAME,@REGISTRATION_NO,@FATHER_NAME,@DATE_OF_BIRTH,@MOBIL
E,@COURSE,@DURATION)";
cmd.Parameters.Add("@STUDENT_NAME", SqlDbType.VarChar,
50).Value = Convert.ToInt32(TextBox1.Text);
cmd.Parameters.Add("@REGISTRATION_NO", SqlDbType.VarChar,
50).Value = TextBox2.Text;
cmd.Parameters.Add("@FATHER_NAME", SqlDbType.VarChar,
50).Value = TextBox3.Text;
cmd.Parameters.Add("@DATE_OF_BIRTH", SqlDbType.VarChar,
50).Value = Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@MOBILE", SqlDbType.VarChar, 50).Value =
Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@COURSE", SqlDbType.VarChar, 50).Value =
Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@DURATION", SqlDbType.VarChar, 50).Value
= Convert.ToInt32(TextBox4.Text);
cmd.ExecuteNonQuery();
cmd.Dispose();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
textBox5.Text = "";
textBox7.Text = "";
comboBox1.Text = "";
TextBox1.Focus();
}

private void button2_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from SEERCADD where
REGISTRATION_NO=@REGISTRATION_NO";
cmd.Parameters.Add("@REGISTRATION_NO", SqlDbType.Int).Value =
Convert.ToInt32(ListBox1.SelectedValue);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
TextBox1.Text = dr["STUDENT_NAME"].ToString();
TextBox2.Text = dr["REGISTRATION_NO"].ToString();
TextBox3.Text = dr["FATHER_NAME"].ToString();
TextBox4.Text = dr["DATE_OF_BIRTH"].ToString();
TextBox5.Text = dr["MOBILE"].ToString();
comboBox1.Text = dr["COURSE"].ToString();
textBox7.Text = dr["DURATION"].ToString();
}

dr.Close();
cmd.Dispose();
}

private void button3_Click(object sender, EventArgs e)


{

SqlCommand cmd = new SqlCommand();


cmd.CommandText = "delete from SEERCADD where
REGISTRATION_NO=@REGISTRATION_NO";
cmd.Parameters.Add("@REGISTRATION_NO", SqlDbType.Int).Value
= Convert.ToInt32(TextBox1.Text);
cmd.ExecuteNonQuery();
cmd.Dispose();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
textBox5.Text = "";
textBox7.Text = "";
comboBox1.Text = "";
TextBox1.Focus();
}

private void button4_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update SEERCADD set
@STUDENT_NAME,@REGISTRATION_NO,@FATHER_NAME,@DATE_OF_BIRTH,@MOBILE,@COUR
SE,@DURATION";
cmd.Parameters.Add("@STUDENT_NAME", SqlDbType.VarChar,
50).Value = Convert.ToInt32(TextBox1.Text);
cmd.Parameters.Add("@REGISTRATION_NO", SqlDbType.VarChar,
50).Value = TextBox2.Text;
cmd.Parameters.Add("@FATHER_NAME", SqlDbType.VarChar,
50).Value = TextBox3.Text;
cmd.Parameters.Add("@DATE_OF_BIRTH", SqlDbType.VarChar,
50).Value = Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@MOBILE", SqlDbType.VarChar, 50).Value =
Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@COURSE", SqlDbType.VarChar, 50).Value =
Convert.ToInt32(TextBox4.Text);
cmd.Parameters.Add("@DURATION", SqlDbType.VarChar, 50).Value
= Convert.ToInt32(TextBox4.Text);
cmd.ExecuteNonQuery();
cmd.Dispose();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
textBox5.Text = "";
comboBox1.Text = "";
textBox7.Text = "";
TextBox1.Focus();
}

private void showRecordToolStripMenuItem_Click(object sender,


EventArgs e)
{
Form3 fd = new Form3();
fd.Show();
}
}
}

You might also like