C# Fill Data Grid View after using input list - c#

I really need your expert help :). Expanding on what I have learnt from querying data sets using adapters and filling a Grid View. I need some help on the following task.
I have a SQL Server Database which I am querying using C#. I already have solid working solutions of by a date range, a specific value. However, the business user would like to search by a list of values they provide as input into a form.
Similar to the below:
adapter.SelectCommand.Parameters.AddWithValue("#mindate", textBox1.Text);
The input will be taken from a text box or similar form based element. There should be no defined limit to the number of values e.g. I don't want to prevent the user from inputting 100 values for example.
By way of example.
User input: doc1.num1.value;doc2.num1.value;doc3.num1.value etc
Note: The document number field may contain a full stop. However, each value will be terminated by a ';'
In the above example, we would run the following query: select employee_id, docNumbers from tableName where docNumbers in (inputlist)
And the output would be:
Record 1: 1, doc1.num1.value
Record 2: 2, doc2.num1.value
Record 3: 3, doc3.num1.value
Thanks in advance guys and gals.

I guess what you are looking for is using an IN clause when doing your query.

Related

Saving SSRS multi select parameter value with wildcard

I have searched and searched and have not been able to find the answer to this. I'm no stranger to SSRS, .Net (c# and vb.net), SQL, etc...been in it for years. I currently have a multi-select report parameter that is populated by a dataset in my report. There are hundreds of entries, so I built it to be driven by a wildcard character in a preceding parameter. Everything works fine right now. My question is this: is it possible to enter a wildcard value, select one (or more) of the filtered values and then store that/those value(s) on selection so that a user can go back and enter another wildcard value and select from a newly filtered list? (Basically, remember what has been selected in the overall dataset before report execution and create some sort of comma-separated list as the final parameter value to be passed to the report) I realize this may be better served in a web app w/a reportviewer control, but I'm trying to avoid deviating from the native SSRS server if possible. Thanks in advance!
The way I might approach this (not actually done it but the theory sounds ok)
Have 2 parameters for user input, your current one and a hidden one called say #filter (visible) and #filterHistory (this is the hidden one)
Have a textbox (formatted like button) with something like "Refine" as the text. Set the action to call your report again but set the #filterHistory to be something like #filterHistory & ", " & #filter. Basically we keep appending the last user input to the history.
Then your report would filter based on both parameters. You'll have to do some parsing of the delimited parameter now to split it out into the constituent parts but you get the idea.
I've no time to build a test report but hopefully that will point you in the right direction. If it doesn't help or work then comment and I'll see if I can knock up a quick example.

C# match datagridview rows to access database

I am trying to figure out the best way to match items on a datagridview to items in an access database. (Think Quicken match transaction)
I import an excel sheet into a datagridview,from there it checks the access db looks for a match - if a match is found then it reports match in a column if not unmatched is reported.
i have tried to count the rows on an sql query - if = 1 then match is yes, but that for some reason will goof up sometimes.
so i am looking for the best way to do this.
Thanks - please let me know if you need any additional info.
There isn't a simple answer to this, and it depends on what your data looks like, and what you consider a "match" to be. As a very basic answer, this is one way to attack the problem. How far you take it is up to you...
Create an algorithm that takes all fields for a row and generates a "key" for it. For example if there are two fields [First], [Last] then perhaps the key would be "Bubba|Gump"
Apply that algorithm to both sets of data (the datagrid records and the access db records).
Compare the two sets of keys to determine what's identical/missing/added.
It's not foolproof but with some additional sophistication it'll take you surprisingly far.

NHibernate - How to write a criteria query to reflect whether a column has a null value or not

I am coding a screen which includes a list of items. Each item includes a button where the user can popup a dialog to enter or read (their previously entered) feedback on said line item. Because feedback contains a substantial amount of textual data and there may be many line items per page I am using AJAX to load feedback on demand.
I would like to have a different icon for the line item's feedback button depending on whether or not the user has left feedback. The goal is to make users aware of what is yet to be entered. I am using NHibernate as my ORM. Is it possible to write an NHibernate query that includes a boolean value indicating whether a database column is null or not? Otherwise is it possible to return the string length for each row, again using NHibernate? I'm using the Criteria API, but any help would be appreciated.
Essentially I am trying to do this:
SELECT id, name, has_feedback is null as has_preview FROM my_table;
it is possible to get the string length using nhibernate functions
session.QueryOver<Foo>()
.Select(Projections.SqlFunction("length", NHibernateUtil.Int32, Projections.Property<Foo>(foo => foo.Name)))
.List();
session.CreateCriteria<Foo>()
.SetProjection(Projections.SqlFunction("length", NHibernateUtil.Int32, Projections.Property(Name)))
.List<int>();

Dynamically create new field search group with multiple filter fields

I searched but I could not find anything similar to what I need so I will appreciate your help.
I have an aspx page that I want to create new textbox fields dynamically upon user request (this is the easy part). The user can ask for any number of fields since they will be used to filter an SQL server table. To make a long story short the table has 23 columns and the user can create multiple textbox for each column so that the general SQL query will search according to the text he will enter in those textbox.
For instance - the user can choose the 'type' field and create 3 textbox which he will enter 'b' for the first, 'c' for the second and 'e' for the third so the query will look something like that:
SELECT *
FROM table_name
WHERE type like '%b%' or type like '%c%' or type like '%e%'
I hope you can understand what I'm looking for,
Any help will be great...
Do a for each loop with all the relevant textboxes. In there you can create the SQL Query and add or type like '%X%' blocks for any nuber of textboxes the user has created. This way the SQL Query will always have the dynamic count of or type like '%c%'

Quickest way to run SQL on a multidimensional array

I want to take a table as represented by a multidimensional string array (column names in another array) and use a SQL SELECT statement to get a subset of rows.
The Catch:
the table is input by the user (different table each time)
the SQL is also input by the user
Do I need to:
Create a table in SQL
Populate the table in SQL
Query the table
or is the a simpler solution? E.g. converting the multidimensional array to a DataTable and then running the SQL on that object?
I think you would be able to use DataTable for this. It's normally used to store data retrieved from a database but you can populate it manually. The best part is the DataTable.Select() method, which allows you to write just the WHERE clause of a query and it will return the matching rows.
You can create your own expression tree representing the query the user enters. This is how Linq works, under the hood. If you could give an example of what your trying to achieve it may help also what your going to write the application in c# for web for example.
For instance if you letting your users enter new rows, in some kind of GUI to a table then you could, do this in a datagrid and enable column filter to achieve the result mentioned above?
In a web app you could have an input box above each column users can enter data to filter that column on.

Categories

Resources