View Full Version : Pass variable between windows form and DataSet TableAdapter SQL where clause
02-24-2012, 05:32 PM
In Visual Studio 2010, I have a windows forms application frmMain.cs with a ComboBox. From the form itself I can access its value with cmbxYear.SelectedValue. I also have a DataSet.xsd file to bind to an rdlc report to a TableAdapter to present view data. The TableAdapter has a SelectCommand that takes SQL code. I need to get the value of cmbxYear.SelectedValue into the WHERE clause of the TableAdapter.
Does anyone know how I can access/pass the variable value from the form into the DataSet TableAdapter SelectCommand WHERE clause?
(I am open to other ideas of how to filter an rdlc report with a variable defined on the windows form.)
02-24-2012, 08:05 PM
I have stumbled upon something that says you can subclass a TableAdapter to change the SQL at runtime. Can someone elaborate on this strategy?
02-26-2012, 10:39 PM
Call me ignorant- but I have no clue what a TableAdapter is (have never used it)... I researching "what" it is (was looking for it's class lib) I found the MSDN overview and it seems as though it is some object GUI wizard thing....
If you are truly making and aspx page (or hell even a windows form- or for that matter anything utilizing the .net framework) why not use
the SqlDataAdapter (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx) class
and the DataSet (http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx) class? I think your life would be easier... the DataSet class has methods for reading/writing both xml and xsd
02-27-2012, 02:28 PM
I am using the OleDb provider for Oracle.
The bind variable should be a question mark ? not :DEPTCODE
The bind variable :DEPTCODE would be valid for System.Data.OracleClient
See full walk through here: http://www.fullstackbusinessdesign.com/forums/ORA-01008.html
Many thanks to Prashant Kumar for this solution.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.