asp.net merging result of 2 database search in one gridview - sql

I have 2 databases from 2 third party providers.
both database have a table with a common unique identifiers (UI).
I want to display table1 of DB1 filters out by the result of a list of unique Identifier retrieved for DB2.
and display the result in gridview.
the initial idea was to insert db2 UI in a virtual table in DB1 and then the usual select db1.table1 - JOIN Virtualtable or where in. but this would be a very slow process considering the search happen with every page post back.
Would it be possible to filter out the result in code behind during gridview.databinding?
or its datasource databinding?

I found a solution:
I Don't use the mark up page Datasource, I use a DataTable in code behind.
Fill datatable with a standard sqlcommand and sqldatareader.
Then while datareader.read I skip rows for which UI does'nt match list of "good" UI from DB2.
Then Bind GridView to Data table.
It even works with gridview paging which i was not expecting to.

Related

Count records from another table to include in the results of a bound table

I am using Visual Studio and have an Access database with a couple of tables that are related. They are using default drag/drop binding using WinForms to the dataset which was automatically generated as well.
I want the parent table to include a column with the count of the number of related records with that ID in the results. The tables look like this if it matters:
I added an additional query to the table adapter (as you can see from the screenshot) that does what it needs to do (without including the linked ID's) thinking that was how to do it. Am I at least on the right track? The query looks like this:
SELECT COUNT(*) AS WorkerCount
FROM (tblJobLaborTech INNER JOIN tblJobLabor ON tblJobLaborTech.JobLaborID = tblJobLabor.JobLaborID)
WHERE (tblJobLabor.JobLaborID = 494)
And of course I need to change 494 to something variable which will match the corresponding record when it runs, but
WHERE (tblJobLabor.JobLaborID = tblJobLaborTech.tblJobLaborTechID)
doesnt seem to preview at all (no value given for parameter)
so i also tried
WHERE (tblJobLabor.JobLaborID = #JLID)
which also doesnt preview.
But that's only the start of the problem. Let's say I can get that part working, how do I get the result of that Scalar query to run for each record in the calling query and return in the dataset as if it were another field in that table?
You don't need to do this using the DB. A datatable can count the records present along a child relation
In your tblJobLabor add another datacolumn (right click, add>>column) and set its Expression property to:
Count(Child(XXX).JobLaborID)
Replace XXX with the name of this DataRelation I've highlighted:
More information can be found by looking at the fairly lengthy documentation on DataColumn.Expression at https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8

Access Query based on ComboBox returning more values than selected in combo box

The following SQL is a simple query but I can't figure out why it is returning more results than it should. The combobox 5 on Form1 has a drop down selection of 1,2,3,4, or 5. If I leave this blank, it will return the entire data set, how if I select 2 as an example, the data set returns data where Field1 is 2 as well as others such as 1,3,4, or 5.
Any thoughts? I am connected to Table1 through an ODBC connection
SELECT Table1.*
FROM Table1
WHERE (((Table1.Field1)=Forms!Form1!CMB5 Or IsNull(Forms!Form1!CMB5)));
Apparently details are important(jk they always are). when creating an ODBC connection, it asks a very important question which is to select a unique identifier. I did not select a unique identifier which was causing the errors with my views. I found the answer here "Why does linked view give different results from MS Access vs SQL Manager?".

Can you insert/update/delete rows in LinqPad via a grid?

Perhaps this is beyond the purpose of LinqPad, but does it have this functionality that is available in SQL Management Studio?
I want to seutp some quick data but don't want to have to write code to do it. I just want to type it in.
Yes, provided your tables have primary keys set.
All you have to do is put your results to data grids (Ctrl+Shift+G) then query the table you want to add rows to. If you're just adding rows and don't need to see existing rows, you can filter it out (YourTable.Take(0)). The key is to make sure that the query type is IQueryable<YourTable>.
You will be presented with a grid of the results of the query. There should be a button up top to Edit Data. There should be an empty row at the end (or you could click on Add Row) where you can enter your data.

Filtring/Searching from a DataGridView

I have a DataGridView in a form which displays a client list with the columns ID, First Name, Last Name, Address. I also included a TextBox to perform the search query. I want to filter my DataGridView based from the given columns using a single TextBox (like a multi data filter/search where I can select from those four columns by typing on a single TextBox).
The question is: am I required to create a binding source for here (I populate my DataGridView using sql database) or is there a way to create filters without having to add a binding source?
You don't populate your grid using a sql database. You populate your grid from a SQL Server database suing something else in between, e.g. a SqlDataAdapter and a DataTable.
A BindingSource is supposed to be a one-stop shop for working with bound data so, while you don't have to use one, I would recommend doing so. Whether it can help you filter your data depends on what it's bound to. The BindingSource doesn't actually do the work of filtering itself but rather passes the work on to the underlying IBindingListView implementation if there is one. For instance, if the underlying data source is a DataTable then the RowFilter of its DefaultView will be used. You could set the DefaultView.RowFilter yourself.
If you want to do all the heavy lifting yourself then you could also search the grid yourself and then hide the rows that don't match. Those rows would still exist though, so you'd have to take that into account when using the data in code.
You have to create a query to retrive a data using like keyword by passing parameter value in form
Example:
pass the parameter from
form(cmd.parameters.add(nvarchar, 20).value = "textbox.text")
create a stored procedure
CREATE PROCEDURE procedure_name
#searchvalue varchar(20)
AS
BEGIN
SELECT
ID, FirstName, LastName, Address
FROM
tablename
WHERE
FirstName LIKE '%#SearchTerm%'
END
This above stored procedure will retrieve all the rows where the FirstName column value corresponds to that name
Then pass the result to gridview

Append Query using Access 2003

I am helping a small school with their database which I created three years ago and that works fine.
I am now creating a attendance register as a new feature to it and am struggling with the update query fields.
I have two tables and one append query which works well with the form I have created. I have combobox to filter the class to check the register which works well. The problem I am faced with is when running the query, it updates all 180 students and not the ones filtered per class.
I need to append the data only for the class selected. Thank You
Please help.
Harry
It seems that you wish to only update or append the rows that match the combobox on your form. You can refer to an open form in a query in MS Access. With your append query in design view, under the field that you want to match and type in Form! followed by the name of your form, another dot or exclamation, and the name of your combo, say:
Forms!Form1!Combo0
In SQL View an append query would look something like:
INSERT INTO Table1 ( AText )
SELECT Table2.AText
FROM Table2
WHERE Table1.ID=[Forms]![Form1]![Combo0]
Similarly for an update query:
UPDATE Table1b
SET Table1b.ADate = Date()
WHERE Table1b.ID=[Forms]![Form1]![Combo0]