title: How to populate listbox through a parametrized stored procedure?
body: <p>I have a Winforms app and an employeeListBox, departmentComboBox and some textboxes to show employee information e.g. fNameTextbox, lNameTextBox..... </p>
  
  <p>I want to populate the employeelistBox through the departmentCombobox selected value and populate the textboxes from the employeeListBox. I have this stored procedure for selection of employees of a department</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[selectEmployee] 
     @departID int
  -- Add the parameters for the stored procedure here
  AS
     -- SET NOCOUNT ON added to prevent extra result sets from
     -- interfering with SELECT statements.
     SET NOCOUNT ON;
  
     -- Insert statements for procedure here
     declare @ErrorCode int
  
  
  
     BEGIN TRANSACTION
        if ( @ErrorCode = 0 )
        Begin
          SELECT 
              EmpID, firstname, lastName, dateOfBirth, Gender, contactNumber, maritalStatus, 
              emailAddress, resentAddress, permanentAddress, nationality, bloodGroup, 
              qualification, Skills, Experience, joiiningdate, probation, departmentID, 
              Salary, paymentMode, active 
          FROM Employee
          WHERE departmentID = @departID
  
  set @ErrorCode = @@error
        End
  
        if ( @ErrorCode = 0 )
       COMMIT TRANSACTION
        else
           ROLLBACK TRANSACTION
  
       return @ErrorCode   
  </code></pre>
  
  <p>and to populate the listbox I wrote this code</p>
  
  <pre><code>    private void selectEmployee(int departID)
      {
          string connString = BL.dbConn.ConnStr;
          DataSet ds = new System.Data.DataSet();
          SqlConnection conn = new SqlConnection(connString);
          conn.Open();
          SqlCommand cmd = new SqlCommand();
          cmd.CommandType = System.Data.CommandType.StoredProcedure;
          cmd.CommandText = "dbo.selectEmployee";
          SqlDataAdapter adapter = new SqlDataAdapter(cmd);
          adapter.Fill(ds);
          listBox1.DataSource = ds.Tables[0].DefaultView;
          listBox1.ValueMember = "EmpID";
          listBox1.DisplayMember = "firstname";
          cmd.Parameters.Clear();
          conn.Close();
          conn.Dispose();
      }
  </code></pre>
  
  <p>I do not know how to pass the departmentid to the stored procedure second how to populate the textboxes from the listbox dataset?</p>