This is a migrated thread and some comments may be shown as answers.

Bind to Query?

2 Answers 127 Views
GridView
This is a migrated thread and some comments may be shown as answers.
bradley baker
Top achievements
Rank 1
bradley baker asked on 01 Mar 2010, 07:59 PM
I have a combo box of part numbers on a form and I want to pass the selected value of the item to a query to build a radgridview.  In ASP.NET this was easy as you just passed in the paramaters.  How would I go about this in WinForms?

Below is the Query that runs and I pass in Part Number and Facility and in ASP.NET it works wonderful.  Would I need to setup an OleDbConnection connection?  Like in http://www.telerik.com/help/winforms/grid_binding-to-datareader.html this example?  How do I pass in the paramaters each time a new PN is selected from the ComboBox.

WITH BOMCTE    
AS   
(    
  SELECT *    
  FROM MBM    
  WHERE BPROD = @PN  
  UNION ALL   
  SELECT MBM.*    
  FROM MBM    
    JOIN BOMCTE    
      ON MBM.BPROD = BOMCTE.BCHLD and MBM.BMBOMM = BOMCTE.BMBOMM  
          
)    
SELECT DISTINCT cast(BCHLD as varchar(100))as ChildID, cast(BPROD as varchar(100))as ParentID, BSEQ as Sequence, IABC as 'ABC Code', ICOND as 'Condition Code', IDESC, IDSCE as '2nd Desc', ICITYP as Type, ICLAS as Team  FROM BOMCTE  
INNER JOIN IIM on BCHLD = IPROD  
INNER JOIN CIC on BCHLD = ICPROD  
UNION ALL 
SELECT DISTINCT cast(ICPROD as varchar(100))as ChildID, cast(NULL as varchar(100))as ParentID, 0 as Sequence, IABC as 'ABC Code', ICOND as 'Condition Code', IDESC, IDSCE as '2nd Desc', ICITYP as Type, ICLAS as Team   
FROM CIC  
INNER JOIN IIM on ICPROD = IPROD  
WHERE ICFAC = @FAC and ICPROD = @PN Order by Sequence 

2 Answers, 1 is accepted

Sort by
0
bradley baker
Top achievements
Rank 1
answered on 01 Mar 2010, 08:11 PM
I converted the Query into a Stored Procedure and have it setup as a TableAdapter, now I just need to know how to pass the values from the combo box to this procedure and rebind the grid each time the combobox changes.
0
Julian Benkov
Telerik team
answered on 03 Mar 2010, 03:54 PM
Hi bradley baker,

You can use an SqlCommand for a scenario concerning stored procedures. 

// 1.  create a command object identifying
//     the stored procedure
SqlCommand cmd = new SqlCommand(
    "YourStoredProcedureName", conn);
 
// 2. set the command object so it knows
//    to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
 
// 3. add parameter to command, which
//    will be passed to the stored procedure
cmd.Parameters.Add(new SqlParameter("@FAC", fac));  //value from combo box
cmd.Parameters.Add(new SqlParameter("@PN", pn));    //value from combo box
SqlDataReader reader = cmd.ExecuteReader();
radGridView1.MasterGridViewTemplate.LoadFrom(reader);

For additional information about ADO.NET commands and parameters, please refer to this article.

Kind regards,

Julian Benkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
bradley baker
Top achievements
Rank 1
Answers by
bradley baker
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or