Nested Loops - Moving To Next Record In While Loop At Any Time?
Mar 25, 2010
Not sure why this is messing with my brain so much today, but I have a SQLDataReader that loops through "Customer" records. In each loop there are MANY other conditions that need to be validated. When a condition fails I want it to move on to the next record in the reader. As you see from my code below, I have simply been exiting the for loop and then checking if I should run other loops all the way down. I want to simply move back to the top of the While Loop for another pass when something like this happens:
I doing a nested for loop to achieve from #123,33.5,1283485089#44.6,Timestamp#124,66.7,timestamp#55.7,timestamp#125,76.4,timestamp#42.8,timest amp whole string to #123,33.5,1283485089#123,44.6,Timestamp#124,66.7,timestamp#124,55.7,timestamp#125,76.4,timestamp#125 ,42.8,timestamp. My code get me back same thing again
Dim i = 0 Dim rsplitdata As String() Dim row, item As String Dim inex Dim rdata As String() = TextBox1.Text.Split("#") For Each row In rdata rsplitdata = row.Split(",") If (i = 0) Then inex = rsplitdata(0) 'rdata(i) = inex + "," + rdata(i) Else rdata(i) = inex + "," + rdata(i) End If i = i + 1 Next For Each row In rdata rsplitdata = row.Split(",") For Each item In rsplitdata TextBox2.Text = TextBox2.Text + item.ToString + vbCrLf Next Next
I cant get my nested loop to output the right code:
If pagesreader.Read() Then ' if subtitle exists then output mydata = "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" While pagesreader.Read() mydata &= "<h2>" & pagesreader.Item("documentcategoryname") & "</h2>" If (pagesreader.Item("documentcat") = pagesreader.Item("documentcategoryid")) Then mydata &= "<p>" & pagesreader.Item("documentname") & "</p>" End If End While End If produces: About Us About Us doccy4 Map Of Medicine doccy5
When I need it to procude: About Us doccy3 doccy4 Map Of Medicine doccy
i have a website that needs to retrive some records in the database, to be specific, example is their Email Address, its more or less 10 records out of 100 records in a table but that number changes from time to time. upon retriving their Email Address, i need to Email them some messages one email at a time.
So to summarized it all:
1. Retrive data from a table (Email Address)
2. Make a Loop on each Email then send Message one email at a time.
give me a sample codes for the retriving and looping process?
Scenario : I have two database tables with one to many relationship. eg:- City and Related news. So I have a gridview(Gridview1) which lists out all the cities and allows edit, delete of the gridview rows. Now since i wanted to display all news for the city, i have a nested gridview as a column in this Gridview1. This nested gridview displays all the news for the cities. And I have edit, delete buttons for this gridview too - So far, good - works fine.
Now what I would like to do is - To insert a new news item for a city. For this, I attached a detailsview to my nested grid(gridview2), and tried to insert. I need the primary key id of city table from the first grid (gridview1) to insert the news into the second database table and I could not access this value from the parent gridview. My gridview1 does not have datakeyname, it is programatically bound.
Also, When the gridview/detailsview is nested, it does not get listed in the event-handler list. So I cannot use say, detailsview1_iteminserting. I do not how to add this event handler
Has anybody done anything similar? When I started, it looked like a pretty straightforward thing - There must be some way to do this. But I just can't get it to work. How do you usually insert into the child table in a one-to-many relationship? Should i just be using two separate gridviews?
I have a GridView1 With Paging allowed, PageSize = 10. And a Nested GridView2. The INSERT function on nested GridView2 works well until the number of record is 10.
On inserting the 11th record, the GridView1 is recorded normally in page 2 of 2. The Nested GridView2 does not fired properly. it appears empty on the 11th record (page 2 of 2), but instead add its record on the last recorded ID on page 1 of 2.
When I remove the paging, everything works well.
How to resolve the paging issue with Nested GridView on "INSERT" record?
I have got a test page setup trying to figure out and learn how to nest gridview.. i finally have a working configuration,but my issue now is that if i select a record from my gridview,the nested gridview opens as expected.But when i select another record from the list in the parent gridview the first selection i made stays open and as i pick more and more, all the nested gridviews stay open.Is there something i can do within my
GridView1_SelectedIndexChanging event to hide the previous gridview and display only the selected row gridview?
Do all comet style applications require a loop somewhere in the application on the serverside to detect updates/changes? how the logic behind a loopless comet style application would work?
I am building a small mass email application for my department. Which basically emails out a notice to a large list of email addresses. Because the company email server limits the amount of email addresses that can be contained in a single email I have to break the list apart into smaller 100 email groups.
I've create the query to pull all email addresses needed, stuffed them into a collection but I am not sure how to grab 100 emails at a time and send it off to another sub to perform the email send before grabbing the next 100.
We have a project that needs to gather survey data. On one particular page of the website, there are 21 questions each with a scale of 1-5 where the user selects one radio button for each question in the table.
The survey is being coded in VB.NET. The data submits to an SQL database. All the radio buttons are similarly named, so only the number changes for the question -- thinking this would make it easier on the back end coding. In the code behind I was hoping to do something to the effect:
We have a project that needs to gather survey data. On one particular page of the website, there are 21 questions each with a scale of 1-5 where the user selects one radio button for each question in the table.
The survey is being coded in VB.NET. The data submits to an SQL database. All the radio buttons are similarly named, so only the number changes for the question -- thinking this would make it easier on the back end coding. In the code behind I was hoping to do something to the effect:
For i = 1 To 21 If rbLWHFQ_Q(i)A1.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A1.Value) ElseIf rbLWHFQ_Q(i)_A2.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A2.Value) ElseIf rbLWHFQ_Q(i)_A3.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A3.Value) ElseIf rbLWHFQ_Q(i)_A4.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A4.Value) ElseIf rbLWHFQ_Q(i)_A5.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A5.Value) ElseIf rbLWHFQ_Q(i)_A6.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A6.Value) ElseIf rbLWHFQ_Q(i)_A7.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A7.Value) ElseIf rbLWHFQ_Q(i)_A8.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A8.Value) ElseIf rbLWHFQ_Q(i)_A9.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A9.Value) ElseIf rbLWHFQ_Q(i)_A10.Checked Then myCommand.Parameters.AddWithValue("@LWHFQ_Q(i)", rbLWHFQ_Q(i)_A10.Value) End If Next i
My research tells me that it's not possible to do what I am wanting without some special coding. I've seen mention of arrays in relation to these types of questions elsewhere, but I'm not familiar enough with arrays to see how they would work in this case.
Am I just going to have to create 21 sets of If...Else statements? :(
Here's what the HTML looks like for a question, if that matters:
As an aside, I know about RadioButtonLists, but in this case I'm needing to style the radio buttons in a special way and can't get it to work when ASP renders the list items.
Updated to show I used it in my code I'm not sure how StackOverflow works with regards to showing how something worked for you, but I just wanted to add this in case others come here looking for the answer. Basically, I used the code below:
Dim radioButtons()() As HtmlInputRadioButton = { _ New HtmlInputRadioButton() {rbLWHFQ_Q1_A1, rbLWHFQ_Q1_A2, rbLWHFQ_Q1_A3, rbLWHFQ_Q1_A4, rbLWHFQ_Q1_A5, rbLWHFQ_Q1_A6}, _ New HtmlInputRadioButton() {rbLWHFQ_Q2_A1, rbLWHFQ_Q2_A2, rbLWHFQ_Q2_A3, rbLWHFQ_Q2_A4, rbLWHFQ_Q2_A5, rbLWHFQ_Q2_A6}, _ }
I created an array with the radio button group names:
Dim radioButtonGroupNames() As String = { _ "@LWHFQ_Q1", _ "@LWHFQ_Q2", _ }
Then in my For...Loop I used:
For i = 0 To 20 If radioButtons(i)(0).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(0).Value) ElseIf radioButtons(i)(1).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(1).Value) ElseIf radioButtons(i)(2).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(2).Value) ElseIf radioButtons(i)(3).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(3).Value) ElseIf radioButtons(i)(4).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(4).Value) ElseIf radioButtons(i)(5).Checked Then myCommand.Parameters.AddWithValue(radioButtonGroupNames(i), radioButtons(i)(5).Value) End If Next i
I am having a change password page in that when the user change his password and click on submit i will show a message and will redirect to main form. But the text which i like to display is not displaying. What i need is i would like to have the page in the same form for few amount of time and then redirect to the desired one.
<script type="text/javascript">function LoadPage() { var v =setTimeout("MovePage()",5000); //will call the MovePage() function after 5 seconds } function MovePage() { location.href='/FedData/newRoutingNumbervalidator.aspx'; } </script>
This code cause double record... i checked my insert code for all tables and it works fine...
and this is insert code:
StoreDO store = new StoreDO(); List<BrandDO> brandList = new BrandBL().SelectBrands(); StoreBL storeBL = new StoreBL(); store.StoreName = txtStoreName.Text;
I am working with asp.net 2008 and sql server 2005 . I get a situation where i have to delete data after 30 days. a suitable query how to do the same. I have go through different query but nothing going right for me.
easiest way to create/update a parent and child record at the same time (like customer with multiple addresses) with least or no code as possible? Both Web Forms and in MVC.
I am querying the SQL database table and returning the result on the webform with a repeater, but I need to display one record at a time and refresh with an update panel and timer to iterate through the rows of the table one at a time at a fixed interval.
Is there another solution to be able to display one record at a time using c# in the webform, but then cycke through the other records one at a time using a timer control and updatepanel?
I tried with no succcess doing a search here on the forum for some answers or pointers. So here goes.
I would like to Calculate total time from a records in a table.
the Table we'll call it "Time Table" may have four rows IE.
Field1 Field2 IN 08:00:00 OUT 12:30:00 IN 13:00:00 OUT 17:00:00
I am trying to display these records in a Child gridview with a total. Is there any SQL that can total time like this? or any other way I can total this?
I've got a DetailsView control on the page, which includes a FileUpload control. Both parts work individually e.g. I can upload a file and insert a record but what I'd like to be able to do is do both with one click - either on the Upload Buttton or on the Insert record text.
I have a button click event:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
But I'm not sure how to call the Insert Record event on the detailsView control.
In my online web-application User is inserting new records and when user enters record system gets current datetime (using below query) and insert into table.