ADO.NET :: Linq Search - Dynamic Query Based On User Input?

Jan 12, 2011

I have two text boxes for the user to enter UserName & First Name, both these fields are optional and not mandatory to fill.

once the user presses the Search button, i execute the following query to fetch matching records.

[Code]....

The problem is, in cases where User leaves both the textbox or one of the textbox empty/blank, in that case that particular field should be removed from where clause.

More like if something is entered then search for that particular record otherwise search for all the records.

View 2 Replies


Similar Messages:

DataSource Controls :: Search Various Database Columns Based On User's Input?

Nov 18, 2010

I have five textboxes(tb1, tb2, ... tb5) on the page, each textbox represent a column in the database table.

I need to search the database table based on the text in the textboxes. User can either enter text in all five textboxes or none.

What's the best way to do a search?

I am thinking for one textbox(tb1), depends on if tb1.text is empty or not, I need to do 2 searches

[Code]....

for two textboxes(tb1 & tb2), depends on if tb1.text and/or tb2.text are empty or not, there are 4 combinations, so I need to do 4 searches

[Code]....

for three textboxes, there are 8 combinations,

Does that mean for five textboxes, I need to do 2 to the power of 5, 32 combinations, 32 if statements?

View 1 Replies

How To Add Persistent Dynamic Controls Based On User Input (not On Intial Page Load)

Oct 13, 2010

I am familiar with creating and persisting dynamic controls on the first load of a page and on subsequent postbacks but I am having trouble with the following user initiated scenario...

In my demo I have a placeholder, two buttons and a literal

[code]....

View 1 Replies

LINQ Query Based On User Preferences?

May 12, 2010

I have a LINQ Query that includes an order by that is based on a user preference. The user can decide if they would like the results ordered asc or desc.

[code]....

View 2 Replies

Web Forms :: Trying To Write A Linq Query That Has Multiple Where Clauses Depening On User Input?

Jan 27, 2010

I have a quick Linq to SQL question. I am trying to write a Linq query that has multiple where clauses depening on user input. What I would intuitively code is:

Dim arrTerms As Array = txtUserInput.Text.Split(" ")
Dim q = From newsitem In db.MyNewsTable _
Where newsitem.Contains(arrTerms) _
Select newsitem
Listview1.DataSource = q
Listview1.Databind()

Unfortunately, though, the "Contains" operattor does not accept an arraylist, or array, or anything but String.

View 1 Replies

Web Forms :: How To Generate Rtf File Based On Input Field (textbox Input By User) C#

May 27, 2010

how can i generate rtf file based on input field(textbox input by user) c#

View 3 Replies

Query For Search Based On Fileds?

Jan 9, 2011

i have 5 Text boxes , all are searching options like

[code]...

View 6 Replies

C# - Dynamic Return Type Based On The Input - Create A Function Which Would Have Two Parameters

Feb 14, 2011

I want to create a function which would have two parameters

public **XYZ** GetOputput(string strToConvert, **ABC**)

What I want from this function, that I will send a string to this function and the datatype in which I want to convert this string [Ex: Int32,Int64, datetime etc..] and the return will be the same as the datatype I have sent as the input parameter.

I want to have something like this in my function:

[code]....

View 5 Replies

ADO.NET :: Dynamic LINQ Query / Use "if Statement" In Linq Query

Feb 11, 2011

I want to use "if statement" in Linq query. How can I do this situation?

For example:

if txtAge.Text=="", I will not use that in Linq Query.

else txtAge.Text!="", I will use that in Linq Query.

View 8 Replies

C# - Avoid Double Control Search In LINQ Query?

Jun 23, 2010

I have a Dictionary<string, bool> where key - control's ID and value - it's visible status to set:

var dic = new Dictionary<string, bool>
{
{ "rowFoo", true},
{ "rowBar", false },
...
};

Some of controls can be null, i.e. dic.ToDictionary(k => this.FindControl(k), v => v) will not work because key can't be null. I can do next:

dic
.Where(p => this.FindControl(p.Key) != null)
.ForEach(p => this.FindControl(p.Key).Visible = p.Value); // my own extension method

but this will call FindControl() twice for each key. How to avoid double search and select only those keys for which appropriate control exists? Something like:

var c= FindControl(p.Key);
if (c!= null)
return c;
but using LINQ.

View 4 Replies

Linq To Sql - 4.0 Dynamic Data Generating Search Or Filtering For Each Columns?

Aug 3, 2010

I am using dynamic data entities linq to sql project. For my test project I have one table, with 10 columns and a single primary key for example. Almost all the columns are varchars.I can get the basic project up and running fine - update, delete, insert etc.ince it has no foreign keys, there are no search filters rendered. I was wondering if there was an easy way to generate a set of filters for the columns for this table. So a First name and last name search box. Is there a way to generate these filters for chosen columns and is there a way to generate these for all the columns

for example, above each of the columns in the grid there might be a text box ( I am not too fussed where the text boxes are rendered as such). Each of the text boxes will act as a filter for that column (doing a SQL 'like')

View 1 Replies

ADO.NET :: Query Dynamic Table In LINQ?

Jan 17, 2011

I have a table created on the fly. The table structure is dynamic.

This is the table structure generated by the end of year 2010

DealerCode, 201010, 201011, 201012

This is the table structure generated by the end of Jan 2011

DealerCode, 201011, 201012, 201101

What I need to do is selecting all data and then bind it into a gridview

To build a LINQ query, we need to drag the table into dbml file first. As we don't know how the table look like, can we add it in dynamically? Are there any other solutions?

View 1 Replies

ADO.NET :: Dynamic Table Name Linq-to-sql Query?

Sep 20, 2010

I am writing a function in which i generate autocode in specific format i want to make this function generalize so that i send tablename and columnname parameter and function return the next code. I am using linq to sql with MVC e.g. i want to make table name and column name dyanamic

[Code]....

View 3 Replies

Generate Dynamic LINQ Query In SharePoint

Nov 25, 2010

I have a page with filters and accordingly to what the user selects, it has to generate a query. I'm using this code:

[code]....

However Linq-To-Sharepoint doesn't convert most of this to CAML and the list I'm querying has more than 50000 items. It takes about 4-8 seconds to retrieve the items which is not acceptable.

I've been trying to generate a dynamic query but so far I haven't been able to get it to work.

With AND and OR operations to generate the query I could put all those conditions on code and increase performance.

View 1 Replies

Select Query In LINQ Based On Foreign Table

Mar 2, 2011

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table. I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum. Here is the way I implement that. I am looking to prevent using "For each".

iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum
Dim objOrderDetails = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1)
For Each OrderDetail As ORM.Entities.OrderDetail In objOrderDetails
If Not OrderDetail.Requests Is Nothing Then
IF OrderDetail.Requests.Last.RequestType="Refund" Then
iRefund -= OrderDetail.UnitCost
End If
End If
Next

View 1 Replies

Forms Data Controls :: Search - Create A Dynamic Query According To Selected Conditions

Jul 1, 2010

I want to create a search form for a table that has many columns. According to input criteria the query will have a where with conditions related to the columns selected or NONE. How can I create a dynamic query according to selected conditions ? is there an example on the net that I can use?

View 2 Replies

Simplify LINQ-To-Entity Query, And Make It Dynamic

Dec 4, 2010

I have this query for getting data through Entity Framework, which works today. Thing is, i want to create the query dynamically, i.e build it up in blocks, but i can't figure out how exactly to do it. I believe if i can somehow save one of the values that i retrieve in the beginning i can do it, but now i retrieve it twice (probably a bit slow as well? Unless the compiler fixes it before quering). Makes sense? Here is the LINQ:

[code]....

I.e based on if various variables have values.

View 1 Replies

ADO.NET :: Make A Linq Query Dynamic In The Pseduo Code

Sep 9, 2010

is it possible to make a Linq query dynamic in the following pseduo code (to show what I'm trying to do)

[Code]....

where a2 and a3 and a4 are being populated from user controls and only one will apply. So query is done by state, zip or by city, but not by more than one, so the other two would be null. So the operator is really "OR" but I haven't found anything on a "or" or "whereOr" operator.

View 9 Replies

C# - Match SQL Columns Based On User Input?

Jan 24, 2011

What i am trying to achieve is that there are 7 columns in my db table. one is primary key and rest 6 are integer columns. Now my application will allow user to input 6 values. I want to compare 6 values entered by user to those 6 integer columns and if in any row 3 or more columns match user's input Primary key of that table is returned..

I have tried using queries, cursor, nested loops and i am still unable to achieve my results..

DB Table Structure.. I am inputting 2,3,7,11,45,65. Number of returned rows should be 5. eg..

UID A1 A2 A3 A4 A5 A6
-----------------------
1 2 3 4 5 6 7
2 2 3 4 55 56 57
3 65 11 45 66 67 68
4 45 7 11 99 98 97
5 7 7 7 7 7 7
6 7 7 7 7 7 7
7 8 8 8 8 8 8
8 8 8 8 8 8 8
9 45 45 0 3 1 2
10 65 7 4 0 0 0

IDs returned should be 1,3,4,9,10

View 6 Replies

Web Forms :: Select CheckBoxList Items Based On LINQ Query Results

Apr 29, 2010

[Code]....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace find.Admin
{
public partial
class WebForm1 : System.Web.UI.Page
{
private
class servicetimeofday
{
public int servicetimeofdayid {
get; set; }
public int serviceid {
get; set; }
public int timeofdayid {
get; set; }
}
protected void Page_Load(object sender,
EventArgs e
{
List<servicetimeofday> servicetimesofday =
new
List<servicetimeofday>
{
new servicetimeofday() { servicetimeofdayid = 1, serviceid = 1, timeofdayid = 1 },
new servicetimeofday() { servicetimeofdayid = 2, serviceid = 1, timeofdayid = 2 },
new servicetimeofday() { servicetimeofdayid = 3, serviceid = 2, timeofdayid = 1 },
new servicetimeofday() { servicetimeofdayid = 4, serviceid = 2, timeofdayid = 3 }
};
GridView2.DataSource = servicetimesofday;
GridView2.DataBind();
var itemstocheck = from
servicetimeofday in servicetimesofday
where servicetimeofday.serviceid == 2
select ne
servicetimeofday.timeofdayid
};
GridView3.DataSource = itemstocheck;
GridView3.DataBind();
foreach (var timeofdayid
in itemstocheck)
{
foreach (ListItem i
in CheckBoxList2.Items)
{
if (i.Value == timeofdayid.ToString())
{ i.Selected =
true; }
}
}
}
}
}

View 10 Replies

C# - Adding Rows To A Table Based On User Input?

Jan 19, 2010

I have a TextBox entry field where the user will enter a integer value. And then there is a "Create" button, which when clicked upon must generate a Table with 2 columns :

"Name" and "Email" being the column headers.

I want each row to have a textbox in each of these columns.

All of this has to happen after the button is clicked. I have discovered that if you dynamically add a control in ASP.NET(I am using C#) then the controls are lost during postback. And I don't know how to prevent that from happening.

Can somebody give me some ideas regarding how to go about adding rows dynamically to a table (I tried using the asp.net Server side table control but ran into the "lost-during-postback" problem - can I try with something else like a gridview ? but afaik a GV will not work without data bound to it )

Point to note is that my table has textboxes for user entry and it is not for showing data ..rather it is for accepting data from the user which will be later used to persist details to the database.

View 1 Replies

Web Forms :: How To Create Controls Dynamically Based On User Input

Apr 20, 2010

could u tell me add controls to a page base on user inputs,

i know the basic of creating a button dynamically but here I have to to add few controls based on user input and how to identify event for each dynamically create control.

View 2 Replies

SQL Server :: Query To Allow User To Search?

Oct 12, 2010

In my webpage I have a textbox where the user can type information that they want to search by. I need to take the user input and build a sql query to return records. I have tested my query in sql and it works hardcoding parameters, however I am having trouble getting the user input dynamically and populating my query string. how to get the user input to populate my query string?

Here is my code:

[Code]....

View 10 Replies

Web Forms :: Create X Amount Of Input Filed Based Off User Selection?

May 15, 2010

I have form in ASP.Net 4 (C# backend) that a user fills out to enter a new game quote into my DB. I have created the form and this lets the user add only a single quote at a time, what I would like to do is give the user a drop down box to let him/her choose to add up to 5 quotes at a time. The problem comes in how to generate the extra input forms based on what the user chooses. I have been going over my ASP.Net 4 book but it really does not cover this.

View 2 Replies

Data Controls :: Render Partial View Based On User Input In MVC

Jan 24, 2016

I want to know that how to render partial view based on where the user navigates. I mean to say if user navigates to Home/index it will load different partial view and if user navigates to Home/contact it will load different partial view on the _layout page. 

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved