Connect to SQL Server Function Using C# Data Grid View
Posted on 2012-03-24
OK, so I'm pretty new to C# development, and I have an issue that I am just not understanding.
I have a SQL Server 2005 compatible DB with a series of tables. The ones that matter are the Users, Compatibility, and Suppliers tables. There is also a view, which pulls the aforementioned tables' data into a View that means something to a program. Finally, I have a function that displays the exact same thing as the view, except that it takes in a variable that filters the data by user (that variable is "@aUser"). The reason I have both a view and a function that display the exact same thing is because I am trying to get it to cooperate with a C# program that I am developing in VS 2010.
Connecting to the DB, viewing the tables, and displaying the view all work perfectly using a DataGridView. My problem comes when I try to use the function. I have no idea how to pass the variable into the function using the DataGridView, along with the BindingSource and the TableAdapter that accompany it.
I read about using the filter property in the BindingSource, but that seems to be only for views and table queries. To that effect, I have no idea how to use a C# variable with the filter property of the BindingSource correctly.
I have no problem using a view or a table query instead of a function, but I also don't know how to use that filter property properly. Without either the proper way to pass a variable to the SQL function in the DataGridView, or the proper way to set up the filter property, my program is at a stand still.
My question is this: How do you pass a C# variable to a SQL Server DB function that is displayed in a DataGridView?
If you don't know that or you think that it's easier/more efficient to use the filter property, then I would love to know what too.
Many thanks in advance for the help and any advice is greatly appreciated.