Click here to Skip to main content
15,886,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using visual studio 2010 C# with MSSQL server.

Hey guys, I am working on a project that displays computer assets held within a database onto a datagrid view in the WindowsFormsApplication. I am trying to filter the datagrid view to make it easier to sift through the database. I am doing this by adding a search function that uses queries on a tableadapter and by using a datagrid paging function which is using a sqldataadaper. Now, I have both the search function and paging working...but they do not work together. Upon running the program, you can search for assets but when you use the paging feature it doesn't allow the search to produce the results in the datagridview.

I have tried many things to fix this issue, such as:
1.) trying to have the paging function use the tableadapter...doesn't work because you cannot add user input variables to a query.
2.)creating sqlcommands within the code...doesn't work because you can't give the tableadapter parameters of a command type.

My question is, is it possible to have a filter function button with a datagrid paging feature? If so, I would love to hear anyone's advice as to go about doing this.

This is the SqlCommand that I cannot place in a query because of the variables "this.mintPageSize" and "intSkip"
C#
   string strSql = "";
   int intSkip = 0;
   intSkip = (this.mintCurrentPage * this.mintPageSize);

   // Select only the n records.
   strSql = "SELECT TOP " + this.mintPageSize +
       " *FROM Assets WHERE [AssetNumber] NOT IN (SELECT TOP " + intSkip +
       " [AssetNumber] FROM Assets)";
}
Posted
Updated 26-Apr-12 15:47pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900