I have a HTML input box that I want to be able to submit URLs into. Only problem is that when I go to submit multiple urls, they are inserted into 1 row in the SQLite database in one big blob.
"http://google.com/http://stack.com/http://aol.com/"
When I want them to be:
Row 1: http://google.com/
Row 2: http://stack.com/
Row 3: http://aol.com/
Essentially, for every URL in the input box to be put into it's own individual row.
How can I achieve this?
This can be done in two steps.
Split the URL(consider it as a string) on the basis of a token ('/').
Then loop over the split string (as per example 3) and save it in DB.
Here is the example code.
var str = 'http://google.com/http://stack.com/http://aol.com/';
var str_array = str.split('/');
Related
I am working on Coded UI for an asp.net web application.
In one of tests I need to validate and verify if the elements of the row are populated right or not.
For instance, suppose my search criteria is such that the Serial Number should start from 001. As soon as I click on Search button my results grid gets populated with all the elements that have 001 in there serial number.
How can I validate that all the elements of the results grid are correct i.e. starting from 001? I know I must use .contains validation criteria.
But what code should I use to run the loop for checking each and every row? in c#.
This answer is heavily dependent upon what you mean by populated right
Is your grid rendering/CodedUI-Defined as a HtmlTable?
If your grid has strict columns you could just ask for the cells matching your criteria.
var cellDef = new HtmlCell(yourHtmlTable);
cellDef.SearchProperties.Add(HtmlCell.PropertyNames.ColumnIndex, "2");
cellDef.SearchProperties.Add(HtmlControl.PropertyNames.InnerText, "YourDynamicValue", PropertyExpressionOperator.Contains);
var matchingCells = cellDef.FindMatchingControls().OfType<HtmlCell>().ToArray();
Assuming your list is somewhat dynamic then you could just validate each entry exists. If you are trying to validate EVERY row, its contents, and formatting. If so you'll just have to cycle every row and ask for each cell according to your criteria.
foreach(HtmlRow row in yourTable.Rows)
{
var idCell = row.GetCell(0);
var decriptionCell = row.GetCell(1);
// your code to match your entries
}
I am using SQL Server. I have 2 columns Passed students and Failed Students in my database.
How to write a query which displays both these columns along with a third column which is Total Students which displays the sum of the entries in the row?
EDIT
It is not allowing me to ask another question.So,posting it here:
I have a hyperlink field in my gridview as below:
[Please refer comment for the code.For some reason it doesn't get posted here.]
Its basically a runId.When I click on this hyperlink I am redirected to a page called RunAnalysis.I want to access the value of the runId which was clicked in this page.
I was thinking of using query string but there is no event as far as I know that is fired on click of the hyperlink.
My question is how do I access the runId value in this page ? Can someone tell me if some event is fired so that I can send a query string.
Thanks.
You haven't given a lot of background information so I am assuming many things in my response.
Here is a simple aggregated result set:
SELECT SUM(Passed) AS [Passed],SUM(Failed) AS [Failed],COUNT(*) AS [TotalStudents]
FROM dbo.Students
Now if there is some grouping you want to do then you would add a GROUP BY clause like so...
I'm creating a new column because I don't know your schema:
SELECT GradeLevel, SUM(Passed) AS [Passed],SUM(Failed) AS [Failed],COUNT(*) AS [TotalStudents]
FROM dbo.Students
GROUP BY GradeLevel
ORDER BY GradeLevel
I have a form that submits parameters to a query, then opens the resulting record in another form. The problem is, whenever there is more than one record it automatically puts the first one into the from without any kind of option to choose the record I want. I have a macro set up on the search button on the first form that submits the parameters to the query and then displays it in the second form, I've tried to set up another macro in between the two, but I don't know if it's possible to set up the expression creator to check the number of rows resulting from a query. Is it possible to modify the query to create a prompt to choose which record I want? Or should I change something else?
This is the query:(automatically created by access)
SELECT CHILD.CHILD_L_NAME, CHILD.CHILD_F_NAME, CHILD.DOB, CHILD.GENDER, CHILD.DAYS_IN_CARE,
CHILD.HOURS_PER_DAY, CHILD.ENROLLMENT_DATE, CHILD.CHILD_ADDRESS, CHILD.CHILD_CITY,
CHILD.CHILD_ZIP, CHILD.CHILD_STATE, CHILD.CLASSROOM, CHILD.SNACK, CHILD.LAST_UPDATED, CHILD.CIN
FROM CHILD
WHERE (((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]) AND
((CHILD.CHILD_F_NAME)=[Forms]![Search]![F_NAME])) OR
(((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]) AND
((CHILD.DOB)=[Forms]![Search]![DOB])) OR
(((CHILD.DOB)=[Forms]![Search]![DOB])) OR
(((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]));
If I understood well your problem and you use VBA it's quite easy to do.
You can create a reduced query based on the query you're creating with the button. This new query should include all and only the fields that allows you to discriminate beetwen the records to show in the 2nd form.
For instance it could include LastName, FirstName and classroom to select between children with same full name.
You can count the number of records of this 2nd query and if greater than 1 it means that you have more than one children to show.
So you can use this 2nd query to populate a combo-box or a listbox for selecting the record you really want to show.
When number of records is 1 you can simply skip the listbox population using an if statement on recordcount.
Next step is opening the form with the selected (or unique) record.
Bye
I am currently dynamically generating labels ids on my ASP site based on the date of the month.
E.g. labelSunday1.ID = "01/07/12"
I am also pulling data down from SQL Server, and storing various values in strings.
E.g. Date = resultDate, stock = resultStock
However, I want to do a find on the page, looking for any Label ID that matches the result of the query, and then display the number of stock in the labels text.
Is there anyway I can search the entire page to see if a label ID matches the resultDate string? I would rather do this search somewhat dynamically, as in the future I hope to dynamically generate many labels on the page.
I was thinking along the lines of:
IF Me.Label.ID = resultDate then
me.label.text = resultStock
but that doesn't work :C
Thanks in advance
The answer was to use "01_01_2013" as an Identifier.
I have a DataGrid, with around 100 differnt entries, I am wanting to loop through each row, and get a field form the database(the field is URL), into a string.Basically I have the code to do a screen scrape using the HTMLAgilityPack, but I want to do this for each row in the database, and update the database based upon the returned screen scrape.
Loop through each row
Store Each URL into a String
Use HtmlAgilityPack to do a screen scrape done
Update Database field "Price" with a value returned from step 3
You can loop through all the rows in your datagrid and add the value of a specific column to a list of strings.
var hyperlinks = new List<string>();
var indexOfColumn = 2;
foreach (DataGridViewRow row in dgvDataGridView.Rows)
{
hyperlinks.Add(((DataGridViewCheckBoxCell)row.Cells[indexOfColumn]).Value);
}
Then use the hyperlinks list and update the database as you require in step 4.
I would say you could update the database inside the foreach statement and not bother adding to the list of hyperlinks, but for 100 rows that could be quite costly and unless you've got batching or something similar so you actually only hit the database every 20 updates or so.