C# - Iterate Through DataTable To Find Elements In List Object?

Mar 24, 2010

As I iterate through a DataTable object, I need to check each of its DataRow objects against the items in a generic string List. I found a blog post using the List's Find method along with a delegate, but whereas that example has a separate class (Person), I'm attempting something like the following using an instance of the string object:

// My definition of the List object.
List<string> lstAccountNumbers = new List<string>();
...
// I populate the List via its Add method.
...
foreach (DataRow drCurrentRow in dtMyDataTable.Rows)
{
if (lstAccounts.Find(delegate(string sAccountNumber) { return sAccountNumber == drCurrentRow["AccountNumber"]; })
{
Found_DoSomething();
}
else
{
NotFound_DoSomethingElse();
}
}

However, with this syntax I'm receiving "Cannot implicitly convert type 'string' to 'bool'" for the if block. what I'm doing wrong and how best to accomplish what I'm trying to do?

View 5 Replies


Similar Messages:

Jquery - Iterate Through JSON Object List Provided By Webservice?

Nov 24, 2010

I have an ASP.NET webservice method that returns a generics list (List'<'Construct>) serialized as JSON, using code such as this:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class TestService : System.Web.Services.WebService {
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetOccupationListJSON(int SOCLevel)
{
Construct NewConstructList = new ConstructList();
DataContractJsonSerializer serializer = new DataContractJsonSerializer(ConstructList.GetType());
MemoryStream ms = new MemoryStream();

[Code]....

I assumed (from looking elsewhere) that accessing the JSON data through the index would provide me with access to the underlying object at that index, so that I can then work with it to access its properties.
However, when i=0 and I do var Construct = data[i]; I get the character at the i position of the data array ([), and in the next iteration I get the second character ({). So clearly I am accessing the elements of a string array rather than the JSON data object.How do I make sure that the data returned by the webservice gets into proper JSON format, so that I can iterate through the object elements within it?

View 1 Replies

C# - How To Write A Single LINQ To XML Query To Iterate Through All The Child Elements

Aug 14, 2010

I am developing asp.net mobile application. I am using XML as a database. I am querying on the XML to access the required elements & attributes by using LINQ to XML in .net. I have the follwing part in my XML file.

[code]....

The similar logic I need for the above defined XML part. In the above XML I want to write the LINQ to XML query which can access the NAME attribute of the 'VALVE' node (<VALVE NAME="PWV">), then it should access the text between 'DISPLAY-NODE' (<DISPLAY-NAME> Production Master Valve </DISPLAY-NAME>), & then it should access the all the attributes of the 'COMMAND' node dynamically ( <COMMANDS USE-TEMPLATE="TRUE" TEAMPLATE-NAME="ValveCommands.xml"></COMMANDS>). All these I want dynamically without explicitly specifying the name of the child node as well as name of their attributes ( similar to the way I written the above query ) Can we write such a code by using LINQ to XML ? It will be better if we can write code for above issue in a single logic ( similar to the way I written the above query ).

View 1 Replies

Load Dynamic List Of Elements AFTER FINISHED Loading Of Several Form Elements?

Mar 1, 2010

I have...a dynamic populated select box several input boxes a submit button form fields are loaded initially using cookies several dynamic populated divs

I want... start loading the content of my DIVs after all FORM elements have been loaded completely (= filled with data, select boxes are populated)

Sample code:

[code]....

View 1 Replies

Iterate Through A Dictionary Object That Can Contain A Object And Enum Types

Jul 20, 2010

Can you iterate through a dictionary object that can contain a object and enum types

foreach(Dictionary<someObject, enumType> myDic in myObjects) {
if(enumType.myType == enumType.Type) {
do something here...

}

View 1 Replies

ADO.NET :: Iterate Data Row To Find Errors

Sep 20, 2010

I have an asp website, and a dataset with a datatable. When I check I after configuring it it shows all the data. But when I run the code I got an exception System.Data.ConstraintException was unhandled by user code Message="Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." I want to figure it out with iterating datarow.

[Code]....

View 1 Replies

Is It Possible To Iterate Through An Unordered List

Jun 21, 2010

Is it possible to iterate through an unordered list like the following in codebehind?

[Code]....

I was hoping to iterate through all the li elements of the ul checking whether NavigateUrl is equal to the current url. If it is, I was going to add a CssClass to give it a different appearance.

I think I know how to compare it to the page's url and to how to add the css class. I'm just not quite sure how you iterate through li items using a HTML Generic control.

View 5 Replies

C# - Iterate All Properties In The List?

Oct 13, 2010

I have List (Of Report). Report has 90 properties. I dont want write them each and every propertiy to get values for properties. Is there any waht to get propeties values from the List

Ex:

Dim mReports as new List(Of Reports)
mReport = GetReports()

For each mReport as Report In mReports 'Here I want get all properties values without writing property names next

View 4 Replies

Web Forms :: Unable To Iterate ThroughIEnumerable And List?

Jan 27, 2010

i m new to asp.net 3.5 linq and dnt worked much on generics.i m using IEnumerable to return set of results.i m binding this IEnumerable type method directly to datagrid source then it works fine.But i dnt knw how to iterate through this collection??Same way i m using List<String> to return columns like this

public List<String> FindImageData()
{
List<String> lst = new List<string> { "" };
ISingleResult<Usp_Patient_Radiology_DisplayResult> imagedata = objimagedata.Usp_Patient_Radiology_Display(p_PatientID);
foreach (Usp_Patient_Radiology_DisplayResult h in imagedata)
{
string Imageid = Convert.ToString(h.ImageId);
string imagefilename = Convert.ToString(h.imagefilename);
string history = Convert.ToString(h.history);
string imagetype = Convert.ToString(h.imagetype);
string oprposundertaken = Convert.ToString(h.oprposundertaken);
string patientposition = Convert.ToString(h.patientposition);
string report = Convert.ToString(h.report);
string xfilmorn = Convert.ToString(h.xfilmorn);
lst = new List<String> {Imageid,imagefilename,history,oprposundertaken,patientposition,report,report,xfilmorn };
}
return lst;
}

but at front end again i dnt knw how to iterate through it.it returns only single row??

with dataset it was quiet easy to navigate but with linq to sql navigation through generic collections is tough.

View 5 Replies

Need To Iterate Through A Server Share And List Every File Within Every Folder ?

Jun 17, 2010

I need to iterate through a server share and list every file within every folder and write each file name with all of its attributes into a database table.I assume that using the FileInfo class and all of it's properties (CreationTime, DirectoryName etc etc) is the best way but I have no idea of how to start.I'm starting to create a web app

View 8 Replies

Javascript - Iterate Through An Image List With 5 Seconds Time Gap?

Sep 27, 2010

I have an array of urls containing locations of pictures on page load. I need to show them to the user in an <asp:img> with a 5 second time interval.

Can this be done with <asp:timer>, or is there any way to do it?

View 3 Replies

ADO.NET :: Find Rows In One DataTable From Another DataTable And Remove Them

Sep 9, 2010

I have a DataTable of available time slots. I have another DataTable of reserved time slots. I need to remove from the list of available slots the ones that have been reserved. The blocks are in 15 minute increments, but one of my problems is that the reservation can be longer than 15 minutes. I've had some luck removing one or two, but not all of the required columns.

Here's my code (it doesn't work right now).

[Code]....

View 1 Replies

C# And Anonymous Types - Iterate Through A DataTable While Manually Building An Anonymous Type

Jan 18, 2010

I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON.

I have been following the excellent article from encosia: http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/

In my Web Method I retrieve my data from the database as a DataTable:

DataTable categoryProducts = ProductViewerAccess.GetCategoryProducts
("AA", 4, 0, Page.ToString(), out howManyPages, "FALSE", 0, "CostPrice", "asc", destinationList);

I then retrieve the data from the DataTable into an anonymous type:

var feeds =
from feed in categoryProducts.AsEnumerable()[code]....

This all works great.

However, I would like to extend the code to perform some evaluation checks (e.g., check that various columns in the DataTable are not NULL) and other pre-processing (e.g., call various functions to build the image URL based on the image ID - which is another column in the DataTable not shown in the code fragment) before I return the resulting rows of the DataTable as an anonymous type to the client-side.Basically, I want to iterate through the DataTable, perform the evaluation checks and pre-processing, while building my anonymous type manually as I go. Or maybe there is a better way to achieve this?

View 2 Replies

How To Find The Number Of HTML Elements With A Name That Starts With A Certain String In C#

Oct 15, 2010

I'm not sure if the topic describes my problem very well but I am creating some HTML elements (textboxes) on the fly with jQuery and I never know how many I will create (it loops through a database). I then want to get all the elements in the code behind and perform some actions (insert them into another database).

I know I can use

string n = String.Format("{0}", Request.Form["hiddenField0"]).ToString();

To get the first textbox but what if Idon't know how many textboxes I have created and want them all? Their name starts with hiddenField plus an incrementing number.

Is there a way to loop through all elements that has a name that starts with a certain string?

View 1 Replies

Javascript - Accessing Elements Of JSON Object Without Knowing The Key Names

Feb 25, 2011

{"d":{"key1":"value1",2":"value2"}}s there any way of accessing the keys and values (in javascript) in this array without knowing what the keys are?The reason my json is structured like this is that the webmethod that I'm calling via jquery is returning a dictionary. If it's impossible to work with the above, what do I need to change about the way I'm returning the data?

Public Function Foo(ByVal Input As String) As Dictionary(Of String, String)
Dim Results As New Dictionary(Of String, String)
'code that does stuff
Results.Add(key,value)
Return Results
End Function

View 2 Replies

Using Javascript (DOM) - User To Drag Individual List Elements From One Box To Another

Jul 6, 2010

I have an asp.net page with several list boxes. I would like to include some javascript on the page that allows a user to drag individual list elements from one box to another. On a normal web page, the script to do this is reasonably simple, however, with the element IDs generated by ASP.NET, I don't know what identifiers to have my script look up?

View 3 Replies

Web Forms :: Adding Dynamic List And Elements In Runtime

Nov 5, 2010

In my Page_Load() event, I'm calling a Sub (in a module UserMenu.vb) that reads an XML file which has the user menu entries. The final menu should be an <ul> with several <li>, some of them with anidated <ul> within. As I understand, I may use a asp:Panel in my page to position a container for this elements I read and in this sub I try to add them using new BulletedList and new ListElement BList.Items.Add(LItem)), but when I get to Panel.Controls.Add(BList) it throws an error that says BList should be inserted in a Form. Why? Aren't they just <ul> and <li>? What other alternative I have to create <ul> and <li> in a specific part of my page?

View 3 Replies

C# - Find DataTable By DataTable.Id ?

Nov 14, 2010

There has to be an easy answer:I want to loop through multiple datatables... example:

for (int i = 1 ; i < 7 ; i ++ )
{
DataTable dt = (DataTable) "dt" + i.toString();
// do something with DataTable dt1 as DataTable
// ie...
int x = dt.Rows.Count
}

The above code obviously does not work.. but how do you find a DataTable like you do FindControl with WebControls??

View 1 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object In Nested Repeater Control Of CheckBox List ...

Sep 24, 2010

[Code]....

I am getting error of in Foreach loop

[Code]....

How to resolve this situation or any other alternative to cum out of this problem.

View 6 Replies

C# - How To Find Null Values In A Datatable

Mar 10, 2011

I have a data table say i have a column like x which is primary key so i should get the row where this x values in empty.

View 2 Replies

ADO.NET :: Find The DataType MisMatch Row In DataTable?

Jan 11, 2011

[Code]....

How find the DataType MisMatch Row In DataTable.

View 1 Replies

JQuery :: JQuery And Custom Attributes/ Find All Input Elements That Will Require Validation?

Jul 14, 2010

to directly get all elements in a form who contains a non html attribute ?

<input .... customAttribute="validateMe">

So I could find all input elements that will require validation.And use this in a loop to add validation to the input's found :

$('input').attr("customAttribute").val() == "validateMe"

I could also write every validation for each object separately, I have only a few elements who uses a required validation but it would be nice that I could do this in one shot instead of repeating the $("input").rules("add .....

View 5 Replies

DataTable.Rows.Find Returns Null

Feb 13, 2010

I have a DataTable for which a PrimaryKey constraint has been set to be a combination of an integer column and a datetime column. When I try to 'Find' a row by saying,

dtFunds.Rows.Find(iContainerIndex)

I get a null value. iContainerIndex has been defined as an object array of size 2 with the integer ID and date values in it.

When I set a breakpoint in my code, I see that the very same values are present in the datatable.

If I try to execute, DataTable.Select() method with the integer column filter, I get a result - but returns no result when called with the date column filter.

What am I doing wrong here? The very same DateTime value is present in the datatable.

View 1 Replies

ADO.NET :: Find Duplicate Rows In DataTable Using LINQ Via VB.Net Syntax?

Jan 15, 2011

I have made a custom DataTable

Dim dt As New DataTable("RizPardakht")
Dim RowID As New DataColumn("tbz_GatiPardakhtID")
Dim FishNo As New DataColumn("tbz_FishNo")

[code]...

View 8 Replies

Save Datatable Object To Sql Database?

Apr 1, 2010

I have a form where users upload a file (csv), then the server does some processing, and generates a datatable. the table will be shown in grid. however, the table's column is unknown, and sometimes, the table is huge. I need show this table in another form.

It seems session variable is not good for this since the table maybe huge. is there a way to write this table to sql, then load it again in the other form?

View 2 Replies







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