SqlConnection sqlnew2 = new SqlConnection();
sqlnew2.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=Training;Integrated Security=True";
sqlnew2.Open();
SqlCommand cmd = new SqlCommand("select DepId from Department where DepName=@DeptName;", sqlnew2);
cmd.Parameters.Add(new SqlParameter("@DeptName", DepNameDropDown.SelectedItem.ToString()));
SqlDataReader sqlread = cmd.ExecuteReader();
while (sqlread.Read())
{
SqlConnection sqlnew3 = new SqlConnection();
sqlnew3.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=Training;Integrated Security=True";
sqlnew3.Open();
string depid = sqlread["DepId"].ToString();
SqlCommand cmd2 = new SqlCommand("select EmpID,EmpName,EmpAddress from Employee where DepId='" + depid + "'", sqlnew3);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd2;
DataSet newds = new DataSet();
da.Fill(newds);
DataListView.DataSource = newds;
DataListView.DataBind();
}
basically
here is the code
i have 2 tables in my data base
one table holds
Dep ID[prmary key]
Dep name
other table contains
EmpId[Primary key]
EmpName
EmpAddress
DepId[Foreign Key]
my cod = first select code will get the DepId
and depid stored as a string
second query will compare the data with that string
and view all the data according to that string
and i need to view it in listbox or gridview
the scenario is like this.....
i have a combo box and when software starts sql data will load to the combo box
when combo box value select
all the data should view in the datagridview..
the problem is when i click the combo box.....
data will not load into the datagridview