我有一个 Winforms 应用程序和一个employeeListBox、departmentComboBox 和一些文本框来显示员工信息,例如 fNameTextbox、lNameTextBox .....
我想通过departmentCombobox 选定值填充employeelistBox,并从employeeListBox 填充文本框。我有这个用于选择部门员工的存储过程
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
并填充我写了这段代码的列表框
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();
}
我不知道如何将部门 ID 传递给存储过程,其次如何从列表框数据集中填充文本框?