List<string> IDs = new List<string>(); XDocument doc = XDocument.Parse(xmlFile); var query = from c in doc.Root.Elements("a").Elements("b") select new { ID = c.Element("val").Value};
How can I convert query to List without loop foreach ?
basically, the InstellingGegevens table gest filled in by some procedure from another server. the thing i then need to do is check if there are new records in this table, and fill in the new ones in Instellingens.
this code runs for like 4 minutes on 15k records. how do I optimize it? or is the only way a Stored Procedure?
this code runs in a timer, running every 6h. IF a stored procedure is best, how to I use that in a timer?
i'd like to be able to check to see if an item with the same id has already been placed in the database, if so to then update the quantity for that item, however due to the fact I have this in a foreach loop it will update the quantity for each item.
When I placed the Command outside of the loop I am unable to use 'ItemID' as it's not in context, is there anyway I can get around this?
foreach (UserItem ItemID in (List<UserItem>)Session["UserSession"]) { ConclusionPage.InsertCommand = "IF EXISTS (SELECT ItemID FROM tblUserItems WHERE UserID='@CurrentUser' AND ItemID='@ItemID') UPDATE tblUserItems SET Quantity = Quantity+1 WHERE (UserID = '@CurrentUser') AND (ItemID = '@ItemID')"; ConclusionPage.Insert(); }
I'm using a foreach to loop through an IList of objects in a Partial View in ASP.NET MVC.
Here's the entire code (Message is one of my classes from the Model).
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<Message>>" %> <% if (ViewData.Model.Count > 0) { foreach (MvcTest.Models.Message m in ViewData.Model) { Response.Write(m.RenderHtml()); } }
ie explicitly declaring a variable for the IList rather than just using the (strongly-typed) Model, and it works fine.
in my asp.net mark up I have a foreach loop that iterates through a simple list. In this foreach loop I am adding a new user control and attempting to pass in the value from the loop. However, this value just wont budge and get inside that damn control!
<%foreach (userInfo i in this.items) { %> <uc1:ItemControl ID="ItemControl" runat="server" UserID='<%#Eval("userID") %>'/> <%} %>
userID is a public property in the control, when it goes to set, the value is just literally :
<%#Eval("userID") %>. I've tried #Bind and =Value but nothing seems to work.
I am trying to do some basic. Display customer testimonials in a table using foreach loop and have a checkbox on each row. Once checked, update the table.
I have a stored procedure of complex type in my entity framework. Here is my View.
I am saving for each user a session with information about his current page viewing.
Each time the user is moving to a new page, I am updating the session with the new page he is right now.
Now, my question is if I can make any loop over all of my users session and answer a question like: How many users are now on page "2.aspx" for example?
I want to get Array Elements by ForEach loop with Counter ..
whislist = dsddsds.Tables[0].Rows[0]["wishtlist_clg"].ToString().Split(','); int i = 0; foreach (string id in whislist) { if (i != 0) { tarsk.Value="1"; } else { tarsk.Value="0"; } whislist =525,1315,1331;
TARSK is an hidden field....
I want if whitelist is not in blank then 1 not equal to 0 is True other false but yet false condition is fire....
as a php developer ive been told to go the MVC route which ive been trying since yesterday. Im using visual web delveloper 2010 express and im using the MVC template project.Ive basically got a news table in MSSQL Express, in there are these fields ID,(Title,Body,PostedOn,PostedBy) all i wanna do is loop through them to put them on the view.Im after a nudge in the right direction, I want to be able to do a SQL lookup in the controller put that data in a DataTable then run a foreach loop on the table to display this on the view. The problem im getting is I know youre not suppsed to put any HTML in the controller and I cant pass the datatable to the view to do the loop in the view.. so where/how do I do the loop.
I'm close to the solution I see where I am going wrong just unsure how to approach it. I want to be able to take a tables worth of data (via DataClasses) and put it in a CSV to download.
A LINQ to SQL query is performed (basically a 'Select All' from tbl_Newsletter), takes those results and the idea is to feed those results, one by one through the foreach which, inside it, is the CSV's definition e.g. List.Add(etc) as you'll see. After which the CSVExporter method is called - which works, as I can Download it, it just wont display any results.
C#: [Code]....
To which I get: Compiler Error Message: CS1729: 'Newsletter' does not contain a constructor that takes '2' arguments
with Newsletter obj = Newsletter.GetAll(); in place of Newsletter obj = new Newsletter();
I get: Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<Newsletter>' to 'Newsletter'
List<ThemeObject> themeList = (from theme in database.Themes join image in database.DBImages on theme.imageID equals image.imageID into resultSet from item in resultSet select new ThemeObject { Name = theme.Name, ImageID = item.imageID}).ToList(); dgvGridView.DataSource = themeList; dgvGridView.DataBind();
The list object populates fine. The datagrid is setup with 2 columns. A textbox column for the "Name" which is bound to "Name" An image column which is bound to the "ImageID" field. When I execute the code I receive the following error on the DataBind() Could not determine a MetaTable. A MetaTable could not be determined for the data source '' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute. I'm not using any dynamicdataroutes as far as I can tell. Has anyone experienced this error before?
I am new to asp.net and was trying to use datagridview in my webform. I was able to bind it to my database but I cannot make the datagridview's buttonfield respond. It seems the grid's SelectedIndexChanged event is not being fired or has issues with postback. Even a very simple statement is not being executed by the program e.g.
I am currently looping through all the controls on my page and setting certain types (TextBox, CheckBox, DropDownList, etc.) to Enabled=False under certain conditions. However I notice an obvious page load increase looping like this. Is it possible to only get certain types of controls from the Page.Controls object rather than Loop through them all? Possibly with something like LINQ?
SELECT COUNT(AdvisorID) AS AdvisorRegisterLast2Days FROM ob_Advisor WHERE CONVERT(varchar,CreationDate,101) BETWEEN CONVERT(varchar,DATEADD(day,-4,DATEADD(day,2,GETDATE())),101) AND CONVERT(varchar,GETDATE(),101)