LoginForm.cs
private void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Count(*) From login where Name='" + txtname.Text + "' and Password='" + txtpass.Text + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
MainForm s = new MainForm();
s.Show();
}
}
private void btnexit_Click(object sender, EventArgs e)
{
this.Close();
}
}
Main.cs
private void Main_Load(object sender, EventArgs e)
{
}
private void btninsert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + Cell + "','" + Address + "')";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Delete from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Deleted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnudate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Update Emp set EmpName='" + Name + "',EmpCell='" + Cell + "',EmpAddress='" + Address + "' where EmpCode='" + Code + "';";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Updated Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
String query = "select * from Emp where EmpCode = '" + Code + "'";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
if (ds.Tables[0].Rows.Count > 0)
{
txtname.Text = ds.Tables[0].Rows[0]["EmpName"].ToString();
txtcell.Text = ds.Tables[0].Rows[0]["EmpCell"].ToString();
txtadd.Text = ds.Tables[0].Rows[0]["EmpAddress"].ToString();
}
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
// string Code = txtcode.Text;
// SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
// string query = "Select * from Emp where EmpCode='" + Code + "'";
// try
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand(query, conn);
// SqlDataReader read = cmd.ExecuteReader();
// while (read.Read())
// {
// txtname.Text = (read["EmpName"].ToString());
// txtcell.Text = (read["EmpCell"].ToString());
// txtadd.Text = (read["EmpAddress"].ToString());
// }
// }
// catch (SqlException ex)
// {
// MessageBox.Show(this, "Exception:" + ex.Message);
// }
// finally
// {
// conn.Close();
// }
//}
private void btnviewall_Click(object sender, EventArgs e)
{
dataGridView1.Visible = true;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Emp";
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void insert_sp_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", Convert.ToInt32(txtcode.Text)));
cmd.Parameters.Add(new SqlParameter("@EmpName", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@EmpCell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@EmpAddress", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
SqlCommand cmd = new SqlCommand("dbo.SP_empSearch", conn);
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
txtname.Text = ds.Tables[0].Rows[0]["EmpName"].ToString();
txtcell.Text = ds.Tables[0].Rows[0]["EmpCell"].ToString();
txtadd.Text = ds.Tables[0].Rows[0]["EmpAddress"].ToString();
}
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empUpdate", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.Parameters.Add(new SqlParameter("@EmpName", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@EmpCell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@EmpAddress", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Updated");
}
catch (SqlException ex)
{
MessageBox.Show("Exception is :" + ex);
}
finally
{
conn.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empDelete", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Deleted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception is :" + ex);
}
finally
{
conn.Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
conn.Open();
String query = ("SELECT * FROM Emp where EmpCode = '"+Code+"'");
try
{
SqlCommand cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr["EmpCode"]).ToString();
//comboBox1.Items.Add(dr["EmpName"]).ToString();
//comboBox1.Items.Add(dr["EmpCell"]).ToString();
//comboBox1.Items.Add(dr["EmpAddress"]).ToString();
}
dr.Close();
dr.Dispose();
}
catch (Exception ex)
{
MessageBox.Show( ex.Message);
}
finally
{
conn.Close();
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Main1.cs
private void label1_Click(object sender, EventArgs e)
{
}
private void btn_insert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + Cell + "','" + Address + "')";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Delete from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Deleted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnupdate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Update Emp set EmpName='" + Name + "',EmpCell='" + Cell + "',EmpAddress='" + Address + "' where EmpCode='" + Code + "';";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Updated Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void search_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
txtname.Text = (read["EmpName"].ToString());
txtcell.Text = (read["EmpCell"].ToString());
txtadd.Text = (read["EmpAddress"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
}
MainForm.cs
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Main obj = new Main();
obj.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Main1 obj = new Main1();
obj.Show();
}
}
}
Program.cs
namespace officemgs
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginForm());
}
}
private void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Count(*) From login where Name='" + txtname.Text + "' and Password='" + txtpass.Text + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
MainForm s = new MainForm();
s.Show();
}
}
private void btnexit_Click(object sender, EventArgs e)
{
this.Close();
}
}
Main.cs
private void Main_Load(object sender, EventArgs e)
{
}
private void btninsert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + Cell + "','" + Address + "')";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Delete from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Deleted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnudate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Update Emp set EmpName='" + Name + "',EmpCell='" + Cell + "',EmpAddress='" + Address + "' where EmpCode='" + Code + "';";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Updated Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
String query = "select * from Emp where EmpCode = '" + Code + "'";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
if (ds.Tables[0].Rows.Count > 0)
{
txtname.Text = ds.Tables[0].Rows[0]["EmpName"].ToString();
txtcell.Text = ds.Tables[0].Rows[0]["EmpCell"].ToString();
txtadd.Text = ds.Tables[0].Rows[0]["EmpAddress"].ToString();
}
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
// string Code = txtcode.Text;
// SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
// string query = "Select * from Emp where EmpCode='" + Code + "'";
// try
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand(query, conn);
// SqlDataReader read = cmd.ExecuteReader();
// while (read.Read())
// {
// txtname.Text = (read["EmpName"].ToString());
// txtcell.Text = (read["EmpCell"].ToString());
// txtadd.Text = (read["EmpAddress"].ToString());
// }
// }
// catch (SqlException ex)
// {
// MessageBox.Show(this, "Exception:" + ex.Message);
// }
// finally
// {
// conn.Close();
// }
//}
private void btnviewall_Click(object sender, EventArgs e)
{
dataGridView1.Visible = true;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Emp";
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void insert_sp_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", Convert.ToInt32(txtcode.Text)));
cmd.Parameters.Add(new SqlParameter("@EmpName", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@EmpCell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@EmpAddress", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
SqlCommand cmd = new SqlCommand("dbo.SP_empSearch", conn);
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
txtname.Text = ds.Tables[0].Rows[0]["EmpName"].ToString();
txtcell.Text = ds.Tables[0].Rows[0]["EmpCell"].ToString();
txtadd.Text = ds.Tables[0].Rows[0]["EmpAddress"].ToString();
}
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empUpdate", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.Parameters.Add(new SqlParameter("@EmpName", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@EmpCell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@EmpAddress", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Updated");
}
catch (SqlException ex)
{
MessageBox.Show("Exception is :" + ex);
}
finally
{
conn.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True;");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empDelete", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@EmpCode", txtcode.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Deleted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception is :" + ex);
}
finally
{
conn.Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
conn.Open();
String query = ("SELECT * FROM Emp where EmpCode = '"+Code+"'");
try
{
SqlCommand cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr["EmpCode"]).ToString();
//comboBox1.Items.Add(dr["EmpName"]).ToString();
//comboBox1.Items.Add(dr["EmpCell"]).ToString();
//comboBox1.Items.Add(dr["EmpAddress"]).ToString();
}
dr.Close();
dr.Dispose();
}
catch (Exception ex)
{
MessageBox.Show( ex.Message);
}
finally
{
conn.Close();
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Main1.cs
private void label1_Click(object sender, EventArgs e)
{
}
private void btn_insert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + Cell + "','" + Address + "')";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Delete from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Deleted Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void btnupdate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string Cell = txtcell.Text;
string Address = txtadd.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Update Emp set EmpName='" + Name + "',EmpCell='" + Cell + "',EmpAddress='" + Address + "' where EmpCode='" + Code + "';";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(this, "Record Updated Successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void search_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp where EmpCode='" + Code + "'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
txtname.Text = (read["EmpName"].ToString());
txtcell.Text = (read["EmpCell"].ToString());
txtadd.Text = (read["EmpAddress"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
}
MainForm.cs
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Main obj = new Main();
obj.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Main1 obj = new Main1();
obj.Show();
}
}
}
Program.cs
namespace officemgs
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginForm());
}
}
0 comments:
Post a Comment