[ Form1.cs ]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace REGISTRATION_FORM
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'masterDataSet.emp_table' table. You can move, or remove it, as needed.
this.emp_tableTableAdapter.Fill(this.masterDataSet.emp_table);
con = new SqlConnection("Data Source=BADBOY\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "submit";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@emp_id", textBox1.Text);
cmd.Parameters.AddWithValue("@emp_name", textBox2.Text);
cmd.Parameters.AddWithValue("@father_name", textBox3.Text);
cmd.Parameters.AddWithValue("@dept", comboBox1.SelectedItem);
cmd.Parameters.AddWithValue("@doj", textBox4.Text);
cmd.Parameters.AddWithValue("@dob", textBox5.Text);
cmd.Parameters.AddWithValue("@local_address", textBox6.Text);
cmd.Parameters.AddWithValue("@paemanent_address", textBox7.Text);
cmd.Parameters.AddWithValue("@designation", textBox8.Text);
cmd.Parameters.AddWithValue("@salary", textBox9.Text);
cmd.Parameters.AddWithValue("@status", textBox10.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Successfully Stored.");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
comboBox1.Text = "Select Department";
}
catch
{
MessageBox.Show("Data not Submitted.Try Again!");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from emp_table",con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
[ DATABASE PART ]
[ TABLE DESIGN ]
[ PROCEDURE ]
create proc m_submitt
@emp_id nvarchar (5),
@emp_name nchar (100),
@status nchar (10),
@doj datetime,
@address nvarchar (300),
@phone_no numeric (10,0)
as begin
insert into m_emp_table (emp_id,emp_name,status,doj,address,phone_no)
values (@emp_id,@emp_name,@status,@doj,@address,@phone_no)
end
0 comments:
Post a Comment