SqlConnection conn;
SqlCommand cmd;
public Form1()
{
InitializeComponent();
conn=new SqlConnection(@"Data Source=DTPC-123P\SQLEXPRESS;Initial Catalog=PrabuDB;Integrated Security=True");
cmd = new SqlCommand();
ds = new DataSet();
}
private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = "Select * from employee";
dr = cmd.ExecuteReader();
while (dr.Read())
{
Program.frm.comboBox1.Items.Add(dr["empname"].ToString());
}
cmd.Dispose();
if(conn.State == ConnectionState.Open)
conn.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = "Select * from employee";
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (Program.frm.comboBox1.Text == dr["empname"].ToString())
{
Program.frm.textBox1.Text = dr["empno"].ToString();
Program.frm.textBox2.Text = dr["empname"].ToString();
Program.frm.textBox3.Text = dr["salary"].ToString();
Program.frm.textBox4.Text = dr["company"].ToString();
}
}
cmd.Dispose();
if(conn.State == ConnectionState.Open)
conn.Close();
}
No comments:
Post a Comment