.net - Optional Where Clause In Query?
Jan 27, 2010
I have an application that does a search of our database (exposed via EF) for records meeting certain conditions. We have two main tables (Jobs and Recipients). Recipients are linked to the Jobs table by a Job ID.The job record has various fields (Process Date, NameJobType). The recipient has a lot of Name and ID fields (e.g. Account Number, Surname, etc)
View 1 Replies
ADVERTISEMENT
Apr 25, 2012
I have an application that does a search of our database (exposed via EF) for records meeting certain conditions. We have two main tables (Jobs and Recipients). Recipients are linked to the Jobs table by a Job ID.The job record has various fields (Process Date, Name, JobType). The recipient has a lot of Name and ID fields (e.g. Account Number, Surname, etc)I want to present a search screen where they see a list of fields to search on. The ASP.net code then sees which textboxes the user typed in (or selected), and builds a query based on that. [code] Where I'm stuck is figuring out how to add in additional where clauses. Should I just use Entity SQL?Can this return strongly typed EF objects as well? And is it possible to return both the Jobs and Recipients objects?
View 1 Replies
Mar 11, 2010
I am learning how to use database. I am using sql server 2005. I would like to know how to make an sql query to the database from vb.net. I have tried some code. what i would like to know is, how to make the sqldataadapter statement with 2 or more where clause.
[Code]...
View 3 Replies
Aug 26, 2009
I have a table DailyTransaction in MsAccess as under: DTDate, DTTime, CustId, Description, Quantity, Price, Amount, AccountNumber, Name I want to extend following query with a Group By clause:I require to display all records in a Listview Group By CustId.Then I require to display all records in a Listview Group By AccountName.e how I can extend following query with Group By clause to achieve the required results
View 4 Replies
Aug 15, 2010
How should I create between clause in my query?
View 3 Replies
Feb 25, 2011
I've written an SQL query with a lot of 'or's in the 'where' clause: i.e. "SELECT * FROM myTable WHERE col1='a' or col1='b' or col1='c'...etc" I'm trying to run a query in access via vb.net, but I keep getting "Query is too complex" error message. I'm guessing I've hit some maximum limit. Anyone know a way around this, other than just to break it down into multiple queries?
View 5 Replies
Mar 20, 2012
I want to set data binding source filter. I want to show only 10 results in descending order by date column.
I know how to use TOP clause in ordinary 'sql' query, but I don't know how to set up filter to binding source.
View 4 Replies
Nov 25, 2009
Dim dataContext As New ACSLostFoundEntities()
Dim query = From s In dataContext.FosterForms() _
Join c In dataContext.Fosters() _
On c.License Equals s.License _[code]....
At the end of this I want to do a Where WantedPets.Contains(criteria), is this possible?
View 1 Replies
Oct 20, 2011
I have a search function de build.We are using pure ASP.NET w VB.NET We have multiple DropDownLists and we're building a search query with whatever was selected in those DDLs. My question is, how can I handle the blank values (unselected dropdownlist values) with the SQL Query ? I'm using AND operators in the query so if anything is blank it'll fail the search. If the dropdownlist has no selected value, i don't want the value to be part of the search. It would be easy to code with just 2-3 parameters, but we're looking thru at least 10 items and doing a SWITCH CASE or multiple IFs would soon become mayhem.
View 1 Replies
Apr 13, 2012
I'm need to do the equivalent of a t-sql statement like this using LINQ:
SELECT * FROM mytable WHERE idnumber IN('1', '2', '3')
so in LINQ I have:
Dim _Values as String = "1, 2, 3"
Dim _Query = (From m In mytable Where idnumber = _Values Select m).ToList()
Not sure what to do with _Values to make idnumber evaluate each value in the string.
View 2 Replies
Aug 25, 2011
Whats wrong with the below query, I am getting this error: Nullable object must have a value.
[Code]...
View 3 Replies
May 10, 2012
I'm currently trying to loop through an array (two values) and use both values in a query inside the loop Right now my code doesn't work. I'm trying to populate dynamically the "appType" parameter within the "SelectParameters" tags of the SQLDataSource, but this won't work.
[Code]...
View 1 Replies
Feb 12, 2011
I am using VS2010 windows application , SQL server 2008 express at backend.I am designing a windows form with fields to search records in database.Say there are 3 fields in the form :
1) material no 2) material group 3)creation date the corressponding table in database with above fields is " Material_master" User can search materials in the database by entering any of the above fields.No I want to write a query where if user doesn't enter anything then my query should work like
"select * from materialmaster "
if only material no is enterd at screen then
"select * from materialmaster where MatNo = materialno "
if both date of creation and material no enterd then
" select * from materialmaster where MatNo = materialno and Date = creationdate "
In other words , field with no values in it should not be accounted in the where clause. Only one query I want to write.How we can achieve this in VB.net windows application?
View 4 Replies
May 4, 2010
I'm adding queries to a wizard generated Table Adapter with WHERE condition that involes the "%" wildcard:
SELECT * FROM Customers WHERE Country = @Country AND CustomerID LIKE @CustomerID
--If I add % after @CustomerID, I get an error message that the --query can't be parsed but if I run the query as above it returns all --the rolls irrespective the value I supplied for the CustomerID column.Only performance counts!
View 20 Replies
Sep 15, 2010
I've got two tables:
tClient:
ClientID Name=============1 John2 Sally3 Joe4 Nick
tInvoice:
InvoiceID ClientID DateAdded==========================1 1 2010/09/012 1 2010/09/023 3 2010/09/01
I'm trying to write sproc where I need the following info:
[Code]...
View 6 Replies
Jul 11, 2011
I built a prototype system with some database queries. Since it was just a prototype and I was very new to databases, I just used a direct string. This is the string I used and it works fine:
command = New OleDbCommand("SELECT * FROM " + prefix + "CanonicForms WHERE Type=1 AND Canonic_Form='" + item + "'", dictionary_connection)
Now, in putting it in a real system, I wanted to use the more secure parametized method, so after some googling I came up with this:
command = New OleDbCommand("SELECT * FROM @prefix WHERE Type=1 AND Canonic_Form=@form", dictionary_connection)
command.Parameters.AddWithValue("@prefix", prefix + "CanonicForms")
command.Parameters.AddWithValue("@form", item)
But all I get is an error for an incomplete query clause. What have I done differently between the two?
View 3 Replies
Mar 26, 2009
I want to pass a comma delemited list of values as a parameter to a query I'm building using the designer in Visual Studio 2008 based on some strongly typed DAL tutorials I was going through. The query is going against a DB2 database. Here's what I want to do:
select * from prices where customer in(?)
It works fine win I pass in 123456 as ?But fails when I pass in '123456' (it is a char field so I don't know why this doesn't work; it must be adding these behind the scenes) or 123456, 123457 or '123456', '123457' I'm adding this page to a portal where all the data access is being done based on the DAL designer model with a BLL that calls it so I wanted to do it this way for consistency.
View 1 Replies
Mar 6, 2010
I am trying to have an optional Date value in one of my sub but since you cant set Date to nothing, this doesn't work. And i cant set it to the Date.minvalue inline.
Private Sub abc (ByVal A As String, Optional ByVal B As Date = Nothing)
End Sub
So, i went and set it to some date in the past.
Private Sub abc (ByVal A As String, Optional ByVal B As Date = #1/1/2001#)
End Sub
what would be the proper way to handle the default value for an optional Date?
View 3 Replies
Jun 26, 2012
I'm trying to convert come vb.net code into C# from another programmers old work but came across optional in one of the functions.[code]...
It seems like instead of using overloading, VB.Net has an option to create it into one method/function. Does C# have a similar equilvalent or do I have to create a method for each possbility?
View 3 Replies
Dec 21, 2009
I have a third party dll that contain a class, SampleClass1
Public Class SampleClass1
Public SomeValue As Double
Public Function Test() As Double
[code]....
My intention is if the dll is found, use it. Else ignore it. However, if the dll is not found, the program throw an Invalid OperationException.
View 7 Replies
Aug 19, 2010
Here is the code:
Function getData(ByVal id As String)
Dim reader As SqlClient.SqlDataReader
Dim statement As String
[code].....
View 1 Replies
Oct 15, 2009
I currently have this XML schema :
<PSC5>
<POI_ORI>
<CIT>LIM</CIT>
</POI_ORI>
</PSC5>
if user want to add a new option, the final schema will be :
[Code]...
View 3 Replies
Mar 30, 2012
I'm looking at an old module to add some new features. I noticed this in a subroutine declaration:sub foo(...,optional fum as integer = 0)the later if not isnothing(fum) then <do something>I'm wondering, will <do something> ever be executed? I'm guessing not, since fum has a default value, but I want to be sure I'm getting this correctly.
View 12 Replies
Mar 16, 2011
It says that I can't have structures as optional arguments.That's really annoying for my program. Isn't there any way to circumvent this?
Sub fa(Optional ByVal colz As System.Drawing.Color = Color.AliceBlue)
End Sub
This example cannot compile
View 14 Replies
Mar 3, 2010
I have a method written in VB.NET. It looks like this:
Shared Sub SomeMethod(ByVal Id As Guid,
Optional ByVal str1 As String = "foo",
Optional ByVal str2 As String = "")
I want to call this method from C# 3.0 and I want it to use its default arguments. I tried passing System.Reflection.Missing.Value, but I cannot cast it as String. Is there any way to do that?
View 3 Replies
Aug 6, 2010
However, I am wondering if there are any workarounds or plans for incorporating this feature into VB.NET in the future?What I'd like to do:
Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, optional ByRef BufferPosition As Integer = 0) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....
In the absence of specifying "optional" inside the actual delegate itself, it'd at least be nice to be able to do it in the function implementation only:
Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, ByRef BufferPosition As Integer) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....
At least this second way, the functions for the delegate will always have a value mapped to each parameter, although some may come from the function side and not the calling side.
View 2 Replies
Mar 14, 2012
How can i create a optional parameter in C# as we create in VB.Net
Public Sub Demo(ByVal a As Integer,Optional ByVal b as integer=3)
End Sub
I want to declare this in C#
[code].....
View 2 Replies
Feb 23, 2012
I am retrieving several properties of a control. Here is how I used to retrieve properties (with pinfo of type PropertyInfo):
value = pinfo.GetValue(obj, nothing)
That worked well, but now I am facing a property that has a optional value, and I get an error message telling me that the number of parameters is incorrect. So I changed my code by this one:
Dim index As Object() = {Nothing}
value = pinfo.GetValue(obj, index)
At this point, I didn't get any error message, but this code doesn't retrieve the good value. It only works if I replace Nothing by the default value provided by the property accessor...
But I don't know in advance what this default value is! And this code is within a function that retrieves properties that doesn't have optional values, so I cannot change the code especially for one case or another..
I am working on .NET 2.0
EDIT: More precisions about the case leading to the problem
Here is an example of property leading to the problem:
ReadOnly Property Foo(Optional ByVal Number As Integer = -1) As String
Get
If Number = -1 Then
[Code]....
With this kind of property, none of the codes above retrieve the good string.
My best guess would be to try the first code for general purposes, catch the appropriate exception, and then dynamically retrieve the default value of the parameter (Number in that case) and its type, so that I can call getValue with this default value.
So, How can I retrieve the default value of the optional parameter?
View 2 Replies
Dec 21, 2010
I tried DbNull.Value but no luck. How do I assign a default value as null to a string parameter that is null in VB.NET? Its litte strange to see that VB does not have anything like plain null as most of the other languages do. Also what is the difference between null and DbNull and Nothing.
View 3 Replies
Aug 9, 2011
What is the standard way to implement optional query parameters in a .NET WinForms application?In other words, only query on a field if the value of a corresponding control is not null.
EDIT: I use a FillBy method which calls a query in my Access database. In the TableAdapter query editor, I just used WHERE (field1 = ?) AND (field2 = ?) ... I just can't find the "hook" to bind form controls to the table adapter query parameters and so that if a form uses the default value to not query on it.
View 2 Replies