Finding Distinct Element From Array Before Select Statement?

Nov 8, 2009

I have an array with wild character at the end. I use the value in this array in Select statement. Some times the array has same values. I want only distinct values in the array before the select statment.
Code:
for i=0 to count
select * from tbl where item like ' " & itemname(i) & "'
next
I need distinct element in itemname array.

View 1 Replies


ADVERTISEMENT

Finding Distinct Values In Array?

Feb 15, 2012

I have a database which need to be assigned into array arr()(), e.g.

arr(0)(0) = aa arr(1)(0) = ab arr(2)(0) = aa
arr(0)(1) = bb arr(1)(1) = ba arr(2)(1) = ba
arr(0)(2) = cc arr(1)(2) = cc arr(2)(2) = cc

I need to find distinct / unique value in each arr(k)(0), arr(k)(1), arr(k)(2); where k=0..2. Then i need to insert the result into array cat as follows:

cat(0)(0) = {aa} cat(0)(1) = {ab}
cat(1)(0) = {bb} cat(1)(1) = {ba}
cat(2)(0) = {cc}

I've tried code below but it doesn't work. The assigning process into array arr()() from DB is OK. Problem only come up if I try to find the distinct value (If Not (cat(j).Contains(ds.Tables(0).Rows(i).Item(j))) ... End If).

For i = 0 To 2
list(i) = New Integer(3) {}
For j = 0 To 2

[Code].....

View 2 Replies

SQL Select Distinct Statement Fails To Execute Properly But Fine Is Access Directly?

Feb 6, 2011

Office 2010; Windows7; Visual Studio Basic 2008 (VB.Net)

[Code]...

The following strSQL string is not working as expected when run in VB.Net Interop to Access: (NOTE: The line-feeds " _" are used below are for reading only - are not in actual code line)

[Code]...

View 14 Replies

C# - Finding Position Of An Element In A Two-dimensional Array?

Jul 15, 2010

Say I have a two dimensional array

[0] [1] [2]
[3] [4] [5]
[6] [7] [8]

Now suppose I want to get the position of the number 6

I know with a one-dimensional array i can use Array.indexOf() but what would my options be with 2-dimensional arrays?

View 3 Replies

Finding Lowest And Highest Element Of Array And Their Indexed Position

Jan 19, 2010

Entered an 5 elements of an array so is has 4 index? I need to find the lowest and highest element of an array and their index position
Example: I enter 1 2 3 4 5
The output should be like this
The lowest is 1 and position of index is 0
The highest is 5 and position of index = 4

View 5 Replies

Creating Array From Select Case Statement?

Jan 10, 2012

Is there a way to pass data from a Select Case statement to an array? i.e. I have a gradebook program I'm working on which specifies that I'm to create a form with a menu that will open another form which has textboxes for 5 student names and 5 grades for each. I need to use an array that holds 5 student names (done), an array of 5 strings to hold each students' letter grade (?) and 5 arrays of 5 numbers to hold each student's set of test scores (done). What I can't figure out is how to get th

Public Class StudentData
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

[code]......

View 8 Replies

VS 2008 Select Case Statement For A 2 Dimensional Array?

Aug 20, 2011

I'm in the middle of making a battleship game, and I'm trying to get picture boxes .visible=True based on the coordinates (that have already been given a nice Try/Catch/Finally error handeling block) of the ships. Example: I have picture boxes in a grid formation that are all red, and my naming convention for them is picR00 for the coordinates (0,0), picR01 for the coordinates (0,1)... et al. Because I'm using a(10,10) for my boolean array, I want the stuff thats false (not marked), those coordinates' red picture box to become visible, and the true have the green ones become visible. Here is what i have so far:

Dim a(10, 10) As Boolean, b(10, 10) As Boolean, c As Integer, x As Integer, y As Integer, ox As Integer, oy As Integer
For c = 1 To 3

[Code].....

View 12 Replies

Randomly Pick An Element From An Array And Can Only Use That Element Three Times

Mar 11, 2010

I need to randomly pick an element from an array and I can only use that element three times,I can randomly pick the element but how do I go about only using it three times.

View 4 Replies

.net - Combining Array Of Arrays Into Single, Distinct Array Using LINQ

Apr 19, 2011

Can this be rewritten any better using LINQ? I'm a C#er trying to think in VB.NET for this current project. It's in an ASP.NET Web Forms .vb codebehind:

Public ReadOnly Property AllowedCategoryIds As Integer()
Get
Dim ids = New List(Of Integer)

[Code]....

View 1 Replies

.net - Linq To Object - Select Distinct

Mar 18, 2010

I can't quite figure out why this Linq Statement isn't working as i would expect:

[Code]....

I would assume that this would create a new collection of anonymous types, that would be distinct. Instead it creates a collection the size of the "ThisParentCollection" with duplicate "MyAnonymousType" in it (duplicate id's).

View 1 Replies

Constraint Violation When Using Select Distinct?

Aug 6, 2009

I have a problem running a simple query: "select distinct payee from table". This query is set up in the dataset and is called GetAllPayee.My code goes something like:

Dim dtSources as new Datatable
dtSources =
Me.TblExpenseRecordsTableAdapter.GetAllPayee
Upon running I get the error:Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.The problem is, I haven't set ANY constraints on either the new datatable, or the dataset table (tblExpenseRecords). i.e. there is no primary key etc.

Can someone please help me out with this problem?I have no problems running the query through the wizard where I can view the results successfully.

View 3 Replies

DataView RowFilter - How To Select Distinct

May 29, 2003

Is it possible to select distinct in the rowfilter method?

I have something like:

VB
'Create a data view so we can get each items name
Dim dvwItemNames As New DataView(dtlItems)
dvwItemNames.RowFilter() = "SELECT DISTINCT Name"

This gives me a syntax error exception. I tried just "Distinct Name" but this had the same result. "Name" is the column name. I would rather do it this way then looping through the entire table and putting the name in an array list or something.

View 11 Replies

LINQ / Select Distinct From Dataset?

Aug 20, 2010

I have a single columned datatable inside a single tabled dataset.I just want to convert this dataset to distinct rows. Here is my code, it gives compile error '.' expected.

Dim query = _
From email In ds.Tables(0) _
Select email.Field<string>("Email").Distinct()

EDIT: I changed to (Of String) and it works... BUT NOW 'query' is an ienumerable collection of characters... not a datatable... so how do I convert back easily without manually doing a loop?

View 1 Replies

Select Distinct In Linq Query?

Jan 4, 2012

I've a collection with the data like this.[code]...

how can select the distinct data using linq?

View 2 Replies

Select Distinct Items From A BindingList?

Jun 5, 2010

I have set up a class to hold song information - artist, title. I then created another class that containg a BindingList(of clsSong). I use this binding list to create a data object that can be used to create an RDLC report. This all works. Now I am trying to remove duplicates from the binding list so they don't show up twice on the report. I can't figure out how to get a distinct list for my report. [code]...

View 3 Replies

Select Distinct Not Get Result Wanted

Jul 4, 2011

I used the following code to select unique values from the database [code]And it does not retrieve the unique values, it remains the same. But if I use only SELECT DISTINCT Author FROM tblBook it works fine.

View 3 Replies

Use Linq For Select Distinct Values?

Mar 28, 2012

I'm pretty new in Linq and the first problem I've is to select the Distinct values from a ObservableCollection( Of T)

I've tried with[code]...

View 2 Replies

Use Select Distinct From A Tables Row In MS Access?

Oct 29, 2010

I have a form with a list box The code loops through a Tables' row and gives me only one of each of the catergories. If more than one of a perticular item exist it only displays one. i would like to use Select Distinct instead just because it would cut down on the time it would take to read the Rows items and still give me the same results I just am not sure how to write it.

[Code]...

View 4 Replies

Finding Unnamed Element In WebBrowser Control?

Jun 25, 2010

I'm writing an application that queries a web page for information. I'm using a WebBrowser control to access the page that contains the info I'm looking for because I need the application to log in to the website and navigate to the desired page.

My code:

Dim wb As WebBrowser = New WebBrowser
wb.Navigate("http://somewebsite:80")
While wb.ReadyState <> WebBrowserReadyState.Complete

[Code].....

View 2 Replies

LINQ To SQL Select Distinct From Multiple Colums?

Apr 2, 2010

I'm using LINQ to SQL to select some columns from one table. I want to get rid of the duplicate result also.

Dim customer = (From cus In db.Customers Select cus.CustomerId, cus.CustomerName).Distinct

Result:

1 David
2 James
1 David
3 Smith
2 James
5 Joe

Wanted result:

1 David
2 James
3 Smith
5 Joe

Can anyone show me how to get the wanted result?

View 3 Replies

Select Distinct Rows From Datatable In Linq

Jul 14, 2010

I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset.[code]How to do thin Linq-to-dataset?

View 3 Replies

VS 2010 Select Distinct Values From A DataTable?

Sep 28, 2010

Is it possible to select distinct values from a DataTable?

View 5 Replies

Filter Out The Distinct Values From An Array To Another Array?

Jul 17, 2009

i have a requirement like i need to filter out the distinct values from an array to another array.

Dim str As String
For Each str In all
If (Not all2.contains(str)) Then
all2.Add(str)
End If
Next

i tried the above logic to get the distinct list but it is telling contains and Add are not the members of system.array?

View 2 Replies

Multiple Select Of HTML Select Element?

Mar 22, 2011

I have a webbrowser control in VB 2010 Windows Form project that loads a webpage. This webpage contains select tags with a few options. I can select one option using:

Dim
cboTemp1 As
mshtml.HTMLSelectElement

[Code]....

But I need to be able to select more than one option (e.g. 1 and 6) in the select tag/element. Is that possible, the Select element has the multiple select option enabled..

View 1 Replies

C# - LINQ Select Distinct While Evaluating Multiple Rows

Jul 11, 2011

I have an EnumerableRowCollection that looks like the following:
VendorCode | GroupType | Variance
01165 G .16
01165 G .16
01165 CH .16
01165 CH .18
07754 G .25
07754 G .25
07754 G .39

Essentially, this is a massive list of vendor codes, their groups, and price variances. I need to compose a query that will create a distinct list vendor codes and group types. The catch, however, is that I need to evaluate all of the variances associated with that particular VendorCode/GroupType to see if they are all the same - it they are not, I need to return some way of signifying that the group has a "custom" variance, otherwise it needs to return the value (ie: if they are all .16, then return .16, if there are multiple values, return "custom")

The result would look like this, based off of the list I showed above.
VendorCode | GroupType | Variance
01165 G .16
01165 CH custom
07754 G custom

I have no trouble getting a distinct list of VendorCode/GroupType - this is what I have so far:
Dim distinctList = From q In query Select q.VendorCode, q.GroupType, (evaluated q.Variance here?) Distinct
(where "query" is an EnumerableRowCollection(Of (anonymous type)))
I'm at a loss, though, on how to evaluate the variance property to get the result that I need?

View 1 Replies

C# - LINQ Select From IEnumerable With Distinct/GroupBy And Sorting?

Oct 19, 2010

My particular example is fairly complex but I think the concept would apply equally to something like a logging system so I'll use that instead for ease of explanation. It's a ficticious example, please don't harp on or agonise over what is achitectually, programatically or morally wrong with the example itself

[Code]...

I don't want to 'cheat' and resort to a long-winded way of doing it when performance isn't critical here and I'm moderately confident it can be done in a single LINQ statement.

View 1 Replies

Linq To Datarow, Select Multiple Columns As Distinct?

Apr 16, 2010

basically i'm trying to reproduce the following mssql query as LINQ

SELECT DISTINCT [TABLENAME], [COLUMNNAME] FROM [DATATABLE]

the closest i've got is

Dim query = (From row As DataRow In ds.Tables("DATATABLE").Rows _
Select row("COLUMNNAME") ,row("TABLENAME").Distinct

when i do the above i get the error

Range variable name can be inferred only from a simple or qualified name with no arguments.

i was sort of expecting it to return a collection that i could then iterate through and perform actions for each entry. maybe a datarow collection?

As a complete LINQ newb, i'm not sure what i'm missing.
i've tried variations on

Select new with { row("COLUMNNAME") ,row("TABLENAME")}

and get:

Anonymous type member name can be inferred only from a simple or qualified name with no arguments.

to get around this i've tried

Dim query = From r In ds.Tables("DATATABLE").AsEnumerable _
Select New String(1) {r("TABLENAME"), r("COLUMNNAME")} Distinct

however it doesn't seem to be doing the distinct thing properly.

View 3 Replies

Sql - Perform An Inline Select Statement In A LINQ Statement?

Jun 24, 2011

I have the following SQL:

[Code]...

I want to put it (the select count statement) in this LINQ statement so I can get the sales count in my linq statement: Dim TheLeads = (From L In DB.Leads Where L.IsDeleted = False Select L).ToList() Is this possible to do in LINQ?

View 1 Replies

Asp.net - Select Distinct Rows From A Datatable With Criteria Involving Multiple Columns Using LINQ

Mar 9, 2012

I have a datatable as shown in the figure. Let me explain my required based on this image. I have 7 rows of data. The rows 1 and 2 contains columns till UnitSqcNo same. I want only row 3 among the two. In general I want select all the rows with distinct model, unittype, unit and rest with greater CompId. ie the table should look like

View 1 Replies

ElseIf Statement Into A Select Case Statement?

Jun 23, 2010

A co-worker wants to convert the following IfThenElseIf statement into a Select Case statement.
Explain why this is not possible.

If temperature = 100 Then
X = 0
ElseIf population > 1000 Then
X = 1
ElseIf rate < .1 Then
X = -1
End If

View 7 Replies







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