C# - Order Datatable By Relevance Using Linq By Column Values Which Are Comma Sperated?

Aug 31, 2010

I have a Datatable that contains a column called Tags, Tags can have values such as

row[0] = Tag1
row[1] = Tag1, Tag2
row[2] = Tag2, Tag3
row[3] = Tag1, Tag2, Tag3
row[4] = Tag4, Tag6

and are seperated by comma's etc..

I have the value of Tags for the current document and have run a query to select all other documents that have either of the Tags in there row. for example lets say the current document Tags are (Tag1, Tag2, Tag3)

so from the example rows above all the rows above are returned apart from row[4] Here is the bit i'm lost with, i now want to sort the datatable by how many tags are matched with the current document. so for the example i've talked about so far they should be ordered

row[3] = Tag1, Tag2, Tag3
row[1] = Tag1, Tag2
row[2] = Tag2, Tag3
row[0] = Tag1


Not used linq before but was told it could do this. so far i have

var query = from c in dt.AsEnumerable()
orderby c.Field<string>("Tags").CompareTo(dr["Tags"]) ascending
select c;

View 3 Replies


Similar Messages:

C# - Putting Datatable Comma Separated Values In A String?

Feb 4, 2011

My datatable consists of a column named "ID". The no. of values in this column varies.Sometimes this Datatable fetches 3 IDs in that ID column, sometimes 2. Now if for example, my datatable has three values as 1,2,3. What I want is to put these three values in a string and separate them by commas as folows:-

string test= "1,2,3";

If Datatable has 2 values, then string should be as follows:-

string test= "1,2";

I did try but in vain.

edit:-

DataTable dt=new DataTable;
dt = obj.GetIDs();
for (int i = 0; i < dt.Rows.Count; i++)
{
string test= "What should be here????";
}
edit 2
foreach(DataRow dr in dt.Rows)
{
string str = str + "," + Convert.ToString(dr("ID"));
}


@Rajeev ::Tried this..it says dr is a variable but used as a method. What's wrong?

View 4 Replies

ADO.NET :: Linq - Order By Column That Contains Query?

Aug 19, 2010

I got a sql table and is trying to sort the data by the column that contains the data entered in a search form.

My code is below:

[Code]....

View 2 Replies

How To Compare Against Column With Multiple Values Seperated By Comma

Nov 22, 2010

I am using rdlc report, i have a column in database which i want to display in the report.

vehicleDamageArea=1,2,3

In the report i need to mark the placeholders with these values .

=iif((Fields!vehicleDamageArea.Value="3"),Chr(253) ,Chr(168)) like this.

But as we know,it will check the whole value 1,2,3="3" not the spilted values.

View 3 Replies

Web Forms :: How To Handle SQL Column With Multiple Comma-delimited Values

Jan 25, 2011

I've inherited an SQL table with a column named "product_codes." It contains 1 or more 4-digit numerals separated by commas (for example, the first record in the table has this in the "product_codes" column:0010,0810

There's a second table containing those product_codes and their corresponding names in a column called "product_name"

I'm trying to set up a FormView that will display an individual record and allow the user to update the record. But when attempting to display a record that has multiple values in the "product_codes" column I get an error, presumably because it can't map the product code to the product name.

[Code]....

View 8 Replies

How To Retrieve The Two Database Column Values To Textbox As Comma Separated String

Dec 30, 2010

If i have two textboxes textbox1 & textbox2 and button1 in my ASP.NET and SQL Server database

Database records are:

ID Date Seats
1 15-Dec-2010 1,2
2 15-Dec-2010 3,4
3 17-Dec-2010 1,2,3,4

I want when i type 15-Dec-2010 in TextBox1 and Click on Button1 then in textbox2 The Output would be retrieve from Database using SELECT query then in TextBox2 the output would be displayed as 1,2,3,4

That the exact i want using SELECT query and VB.NET.

View 3 Replies

DataSource Controls :: Move 1 Column Values To Another Column In Datatable?

Mar 31, 2010

i have a datatable with several columns and rows. now i want to copy the last column fully (all rows) and create the new column with that values.

it means last column values sholud be moved to new column (now this is the last column).

View 2 Replies

Linq To DataTable Not Producing Distinct Values?

Oct 19, 2010

I have a datatable which has been dynamically generated from FoxPro tables using a UNION Select statement. e.g.

SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM Z ORDER By v_alue1

This produces a datatable with about 100 rows, each containing many fields, one of which is c_olor. From this datatable, I would like to select the distinct colors and then output in a dropdown.

I have a public class Color which just has one property which I can then use as the DataTextField and DataValueField for the dropdownlist

[code]...

However this never results in the distinct colors.

I have searched and searched for what I am looking for, and this seems to be one of the methods to produce a distinct set of results, but this and the others do not work.

My reasoning behind getting the colors this way, is that I need to get various other distinct values from the same UNION SELECT datasource, so would just do one DB call, cache the results, and then just used this cached datasource to retrieve all my distinct values.

View 2 Replies

ADO.NET :: Distinct Values From A Column In Datatable?

Sep 21, 2010

I have a datatable dt with 4 columns. I want to retrieve only distinct values from column1 of datatable.

How can I achieve this using c# code?

View 3 Replies

Adding Values For Datatable Column?

Dec 27, 2010

i have a sum column in my datatable and want to add the values?

is compute a good method to use?

View 1 Replies

Web Forms :: Sort A Data Table Based On A Particular Column Which Has Integer Values In Ascending Order?

Oct 22, 2010

How do I sort a data table based on a particular column which has integer values in ascending order?

I wrote this:

'Sort the datatable based on sequence id leadtable.DefaultView.Sort ="Id" But it doesnt seem to work Datatble is defined as:

[Code]....

View 9 Replies

C# - Adding A Way To Preserve A Comma In A CSV To DataTable Function

May 17, 2010

I have a function that converts a .csv file to a datatable. One of the columns I am converting is is a field of names that have a comma in them i.e. "Doe, John" when converting the function treats this as 2 seperate fields because of the comma. I need the datatable to hold this as one field Doe, John in the datatable.

Function CSV2DataTable(ByVal filename As String, ByVal sepChar As String) As DataTable
Dim reader As System.IO.StreamReader
Dim table As New DataTable
Dim colAdded As Boolean = False
Try
''# open a reader for the input file, and read line by line
reader = New System.IO.StreamReader(filename)
Do While reader.Peek() >= 0
''# read a line and split it into tokens, divided by the specified
''# separators
Dim tokens As String() = System.Text.RegularExpressions.Regex.Split _
(reader.ReadLine(), sepChar)
''# add the columns if this is the first line
If Not colAdded Then
For Each token As String In tokens
table.Columns.Add(token)
Next
colAdded = True
Else
''# create a new empty row
Dim row As DataRow = table.NewRow()
''# fill the new row with the token extracted from the current
''# line
For i As Integer = 0 To table.Columns.Count - 1
row(i) = tokens(i)
Next
''# add the row to the DataTable
table.Rows.Add(row)
End If
Loop
Return table
Finally
If Not reader Is Nothing Then reader.Close()
End Try
End Function

View 6 Replies

The Column Is Dragable Means The Order Of The Column Can Be Changed By Drag And Drop?

May 5, 2010

i am making a website and i get a requirement that in GridView or ListView whatever control you used but the column is dragable means the order of the column can be change by drag and drop.Along with that i want to give option to the client that add more column if he check mark some column then that column should be added client side.So i am looking for some dll in ASP.NEt or Jquery for <table> Operation or javascript anything help me out

View 1 Replies

Forms Data Controls :: Set A Column In A DataTable To Be A Primary Key For An Existing Datatable

Apr 2, 2010

If I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?

View 1 Replies

DataSource Controls :: Compile In Order To Get The System.Linq.Dynamic Namespace / Dynamic Linq Error

Apr 20, 2010

I've added the Dynamic.cs file to my project and have set it's Build Action = Compile in order to get the System.Linq.Dynamic namespace.

However, when I try to use any of the new code I am getting an ambiguous call error; see below.

[Code]....

View 2 Replies

DataSource Controls :: Datatable Sort In A Particular Order?

Oct 22, 2010

How do I sort a data table based on a particular column which has integer values in ascending order?

I wrote this:

leadtable.DefaultView.Sort = "Id"

But it doesnt seem to work, it displays fine but when i get try to get the values of the sorted datatable in an array they dont come in an sorted ordere Datatble is defined as:view plaincopy to clipboardprint?

View 3 Replies

DataSource Controls :: Order By In Merged Datatable

Feb 4, 2010

after i merged two tables i want to order the entries by a column named "time" and i don't know the syntax for it.

View 2 Replies

Changing The Order Of Columns When Binding DataTable To A GridView

Mar 31, 2010

How is it possible to change the displayed order of columns from a DataTable?

For example, dataTable "dt" contains two columns "a" and "b". I bind it to a GridView like this:

gridView.DataSource = dt;
gridView.DataBind();

But I'd like the GridView to display "b" first (leftmost).

Important point: I'm using this to export to Excel and there's no actual output to screen, using:

HtmlTextWriter htw = new HtmlTextWriter(sw);
gridView.RenderControl(htw);

View 2 Replies

SQL Server :: How To Read Comma Delimited Data From A Column

Feb 23, 2011

I am creating a BLOG and Forum, and am using tags similar to this and most other sites, I just need to know how to retrieve the tags from a culmn if the tags are stored with commas separating them, I am sure I read about it somewhere but was unable to find it.so the column would be:

tag1, tag2, tag3, etc.....

I would need to be able to:

1. Store tags, and add-on to tags already in the column

2. retrieve the tags as a list, or separately

View 5 Replies

DataSource Controls :: How To Create A Comma-delimited Column For Each Datarow (SQL)?

Feb 3, 2010

[Code]....

View 8 Replies

DataSource Controls :: Split Recods If Column Contains Comma Else Display As It Is?

May 31, 2010

I have table that's contains 2 columns Name and IDs (VarChar(10)) values are stored as

Name IDs

Test1 Test2 1

Test2, Test3 2
Test3 Test4 3
Mohd Farooq 1,2,5

My requirement is to display as below
Name IDs
Test1 Test2 1
Test2, Test3 2
Test3 Test4 3
Mohd Farooq 1
Mohd Farooq 2
Mohd Farooq 5

View 7 Replies

Web Forms :: Get Count Of Number Of Items In A Column Which Is Separated By Comma?

Sep 27, 2012

In a column, have many items separated by comma or whitespace. How to get count of the number of items that is separated by comma or whitespace.

For example, test column has data like 123456, 543213, 678895

How to count as 3

View 1 Replies

ADO.NET :: How To Add Column To DataTable Inside Loop Then Sort On New Column

Mar 22, 2011

I am grabbing an XML feed an throwing it into a dataset. I am looping through the datatable that is in the dataset and adding a column to the datatable (Distance) that is the result of a calculation. What I then need to do is sort the dataset on the new column (Distance) I added, but it is not working... Here is a sample of my code.

[Code]....

View 1 Replies

ADO.NET :: How To Order An Arraylist With Linq

Sep 9, 2010

Is there a way I can sort this query result in Linq? I'd like to sort in descending order by the .Count parameter:

[Code]....

View 2 Replies

Retrieve Record In Comma Separated String From Multiple Database Column?

Dec 30, 2010

i have textbox1 and textbox2 and 8 checkboxes in my ASP.NET (VB.NET) webform. i want to retrieve the seats on the particular dates means if i enter 11/12/2010 in textbox1 then in textbox2 the output would be from seat_select column, let say (1,2,3) where date would be 11/12/2010 If i enter 13/12/2010 in textbox1 then in textbox2 the output would be 1,2

View 3 Replies







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