hi,
i am new in c#. i need help to complete my final project on database as i cant figure out how to do my coding for combox drop list.
I have my databse in sql. i have created form with combobox droplist for the department list and a view button which suppose to pop up the list of employees belong to the department.
My question:-
how to do the code for the button? and getting information from my database.
for the combobox droplist ..i added the dept list manually as i cant bind them as i get repeated department name as some employees with same dept.
Look forward to some help with clear code sample.
thank you
Loading
Dorababu MekaPosted Feb 16, 2013, 6:32 AM
Try the following assuming that you have done for the first i.e selecting a dropdown value and submitting. In your form that you would like to show the data create an object
public string optionType { get; set; }
also place a datagridview to show the data
In your main from i.e dropdown form on button click write this
// Replace as per needed here
Form3 frm3 = new Form3();
frm3.optionType = comboBox1.Text;
frm3.ShowDialog();
now in the form where you would like to show the data under form load code this
private void Form3_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand("select firstname from tblStudent where department='" + optionType + "'", con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.AutoGenerateColumns = false;
}
Dorababu MekaPosted Feb 16, 2013, 6:07 AM
prem kamalPosted Feb 16, 2013, 5:41 AM
thanks. but my situation is like this and would appreciate if you can show me howto do it.
i have database sql with 5 columns which is Emp ID, First Name , Last Name, Designation & Department.
I have created a window form with button (view) and combobox (droplist of the department which is added manually)
so, no i need to do the code for the button..if the user choose HR dept at the droplist and click the view button so the name list appear in messagebox..
so can you help if i need to get this date using sql database.
Thank you.
Dorababu MekaPosted Feb 16, 2013, 12:41 AM