have 5 datatables and will add up more, what i need is to copy the content(rows) of the each and every datatable in a separate datatable. All the datatable columns are same. Is that possible without foreach statements. We can achieve the results in foreach
but the datatables will contain more rows, so iterating each and every datatable will affect the performance.he code i implemented is exact thing i need, but without foreach statement. To copy content of each and every datatable and put the content in a final datatable
DataTable dat = new DataTable();
DataRow Dr = dat.NewRow();
dat.Columns.Add("c1", typeof(string));
Dr[0] = "01";
[code]...
I have taken a DataTable control and have added colums to it. Now i want to add rows to that DataTable but when i am trying to create a DataRow of DataTable, an error is generated, showing "Value of type 'System.Data.DataRow' cannot be converted to 'dataRow'".
I have a FormView control in an ASP.NET page. I use the InsertItemTemplate and EditItemTemplate to provide data manipulation functionality, and it is working very well. I would like to allow the user to "Copy to new" from an existing item. In other words, I want the user to be able to display an item as if they are going to edit it, then, if they click a "Copy to new" button, it will load the information from that item into an "Insert" form so they could just change the bits of data that they want, and insert the new item.
The data objects we are dealing with are fairly large so, providing this functionality will save the user a lot of data entry misery.
I have experimented with copying the existing EditItemTemplate controls in the Copy button's click event, storing them, and writing them to the new InsertItemTemplate controls, once the form is reloaded (in the Page_PreRender event). But this is pretty ugly stuff. There has to be a better/simpler way.
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.
how can i replace the response.write with any label or literal? when i tried to use a literal on the code it displays one single string not all of the strings that's been splitted.
I have a static class with a static get property, and in this property, I do this:
// property body { // HttpContext.Current is NOT null Parallel.ForEach(files, file => { // HttpContext.Current is null var promo = new Promotion(); }); // HttpContext.Current is NOT null }
This static class doesn't undergone type initialization until a view uses this property.
The problem is that Promotion's static constructor, which is initialized the first time a new Promotion() is created within the Parallel.ForEach(), uses HttpContext.Current. When promo is instantiated within the scope of this Parallel.ForEach(), HttpContext.Current is null, and new Promotion() therefore causes an exception.
HttpContext.Current is not null within the static get property because it's not called until the view uses it (and there is therefore a HttpContext.Current).
If Promotion used HttpContext.Current in its instances instead of its static members, I could probably just pass HttpContext.Current into the new Promotion() constructor:
var context = HttpContext.Current; Parallel.ForEach(files, file => { var promo = new Promotion(context); });
But since static members of Promotion need HttpContext.Current, I can't. I could probably redesign the Promotion class to change the static members that need it to be instance members, but they are static for a reason--there would be a large performance penalty if all the members that were static had to be defined instead on each instance each time a new Promotion was instantiated.
What are the possible workarounds for this? I didn't realize HttpContext.Current would be null within the scope of Parallel.ForEach().
What am I missing here. I just want to pull the first one returned from row.detail in an MVC2 view, how would i do this without a foreach loop? This code currently works, but i just want the first one listed. I know this may be simple, but i am drawing a blank.
if (Model.App != null) { foreach (var row in Model.App.Instructions) { <input type="hidden" value="<%= row.Detail %>" id="ixd" /> } }
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<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 ?
I'm using Entity to SQL to retrieve some data from the database and i'm using it to fill an DataList.The query bellow is correct and working properly. My problem is when i try to convert it to an List.I've tried with foreach(EncomendasProdutos ec in produtos)but with no sucess ("Cannot convert type 'AnonymousType#1' to 'cenatolim.EncomendasProdutos'").
Is it because i'm joining tables? I need to save the values of some fields like IVA and Final from all products of the result, but i don't know how.[Code]....
public DataRow GetItem(ENTITY_TYPE EntityType, long EntityID)
This fetches a row and returns it. Pretty simple.
However I can't test in the method to see if the row was fetched, as the method has to end with:
return ds.Tables[0].Rows[0];
If the row wasn't fetched, this errors as there is no row at position 0.
I can't do this:
DataRow dr; if (ds.Tables[0].Rows.Count == 1) { dr = ds.Tables[0].Rows[0]; } return dr;
.. because then I get an error that I can't return an uninitialised variable (dr).
I can't stipulate what the columns are and return a "blank" DataRow as far as I can see, because it's dynamic so I don't know what the columns will be. There doesn't seem to be a way to instantiate the DataRow return var except by assigning, er, a DataRow. Which I may not have.
I don't really want to switch to using the ItemArray and pass arrays about, I'd rather just pass the DataRow object as this is in a loop which might process a lot of rows.
[url=http://www.upanh.com/upanh_untitled/v/6tu4czcr7sd.htm][img]http://ca7.upanh.com/16.993.21338424.vtS0/untitled.jpg[/img][/url] [code] private Controller ctl = new Controller(); ..... DataTable db1 = new DataTable(); ArrayList arr1 = new ArrayList(); arr1 = ctl.getAlljob(); db1.Columns.Add("IDjob"); db1.Columns.Add("product"); .... db1.Columns.Add("report"); foreach (Job j in arr1) { DataRow dr = db1.NewRow(); dr["IDjob"] = v.getjobid.ToString(); .... dr["report"] = "Report"; <=== it show "Report" but i want to it show as report linkbutton db1.Rows.Add(dr); } GridView1.DataSource = db1; GridView1.DataBind();[/code]
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?