G
Guest
Hello
I am working on a windows application with C#.net. What I need is to display a list of data in 2nd combo box based on the choice of the 1st combo box. I used SqlCommand object and SqlDataReader. It works fine. But when I use DataAdapter and DataSet objects, it doesn't work. Here is my code
**********************************************************************************
In SQL db, there is a stored procedure
CREATE PROCEDURE [proTest]
@company as nvarchar(255)
AS
select distinct SubCompany from tblCompany where Company=@compan
In the applications
SqlConnection objConnection = new SqlConnection(connString)
SqlCommand cmdProduct=new SqlCommand(proTest, objConnection)
SqlDataAdapter daProduct=new SqlDataAdapter(cmdProduct)
daProduct.SelectCommand.Parameters.Add("@company", SqlDbType.NVarChar, 255, "Company")
daProduct.SelectCommand.Parameters["@company"].Value=1stComboBox.Text
DataSet dsProduct=new DataSet()
daProduct.Fill(dsProduct, "Product")
2ndComboBox.DataSource=dsProduct.DefaultViewManager
2ndComboBox.DisplayMember="Product.SubCompany"
Does anyone has idea what is the problem? Thanks in advance
-
I am working on a windows application with C#.net. What I need is to display a list of data in 2nd combo box based on the choice of the 1st combo box. I used SqlCommand object and SqlDataReader. It works fine. But when I use DataAdapter and DataSet objects, it doesn't work. Here is my code
**********************************************************************************
In SQL db, there is a stored procedure
CREATE PROCEDURE [proTest]
@company as nvarchar(255)
AS
select distinct SubCompany from tblCompany where Company=@compan
In the applications
SqlConnection objConnection = new SqlConnection(connString)
SqlCommand cmdProduct=new SqlCommand(proTest, objConnection)
SqlDataAdapter daProduct=new SqlDataAdapter(cmdProduct)
daProduct.SelectCommand.Parameters.Add("@company", SqlDbType.NVarChar, 255, "Company")
daProduct.SelectCommand.Parameters["@company"].Value=1stComboBox.Text
DataSet dsProduct=new DataSet()
daProduct.Fill(dsProduct, "Product")
2ndComboBox.DataSource=dsProduct.DefaultViewManager
2ndComboBox.DisplayMember="Product.SubCompany"
Does anyone has idea what is the problem? Thanks in advance
-