G
Guest
Hello,
I am working on a windows application with C#. What I need is to display a list of data in 2nd combo box based on the selection 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=@company
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";
When I put each line of code into separate try/catch block, I did find that the problem is on this line of code
'daProduct.Fill(dsProduct, "Prodct")'. But I can't figure out what is wrong with this. Does anyone have any idea about it?
Thanks in advance!
Jane
I am working on a windows application with C#. What I need is to display a list of data in 2nd combo box based on the selection 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=@company
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";
When I put each line of code into separate try/catch block, I did find that the problem is on this line of code
'daProduct.Fill(dsProduct, "Prodct")'. But I can't figure out what is wrong with this. Does anyone have any idea about it?
Thanks in advance!
Jane