How i can add a catch block inside the for each block ( in progress 4gl) when the error is occurs i want to move to the next records - openedge

I have tried
DO ON ERROR UNDO , THROW:
FOR EACH ttFileData NO-LOCK:
CREATE ttCustomerDetails.
ASSIGN
ttCustomerDetails.ttcustmId = INTEGER (ENTRY(2 , ttFileData.ttLine))
ttCustomerDetails.ttfirstName = ENTRY(3 , ttFileData.ttLine)
ttCustomerDetails.ttgender = ENTRY(6 , ttFileData.ttLine)
ttCustomerDetails.ttsalary = DECIMAL (ENTRY( 13 , ttFileData.ttLine))
ttCustomerDetails.ttcountry = ENTRY(5 , ttFileData.ttLine)
ttCustomerDetails.ttage = INTEGER ( ENTRY (7 , ttFileData.ttLine))
ttCustomerDetails.ttTenure = INTEGER (ENTRY (8 , ttFileData.ttLine))
ttCustomerDetails.ttDOB = obj1custmomerDetail:calculateDOB(INPUT ttCustomerDetails.ttcustmId , INPUT TABLE ttCustomerDetails)
ttCustomerDetails.ttemail = obj1custmomerDetail:createEMAIL(INPUT ttCustomerDetails.ttcustmId , INPUT TABLE ttCustomerDetails).
CATCH e AS Progress.Lang.Error:
MESSAGE "error:" e:GetMessage(1) VIEW-AS ALERT-BOX.
FIND NEXT ttFileData.
END CATCH.
END.
END.
The error I'm getting is
FIND cannot be processed for a FOR EACH mode record.

You don't need the
FIND NEXT ttFileData.
inside the CATCH block. The CATCH block handles the error and the FOR EACH loop will just move to the next iteration - which moves to the next record.

Related

How to check if form is an input file field? Asp Classic

I have some code that checks input values before I insert it into the db. And it works as it should, it checks all form inputs, but I would like it to exclude all the file upload inputs, so it doesn´t check the values of file inputs when I upload an image. But I don´t know how to make it work, so any input really appreciated. Thanks.
This is what I have now.
Dim BlackList, ErrorPage
BlackList = Array("#","$","%","^","&","|",_
"<",">","'","""","(",")",_
"--", "/*", "*/", "##",_
"cursor","exec","execute",_
"nchar", "varchar", "nvarchar", "iframe", "char", "alter", "begin", "cast", "create", "insert","delete", "drop", "table"_
)
Function CheckStringForSQL(str,varType)
On Error Resume Next
Dim lstr
' If the string is empty, return false that means pass
If ( IsEmpty(str) ) Then
CheckStringForSQL = false
Exit Function
ElseIf ( StrComp(str, "") = 0 ) Then
CheckStringForSQL = false
Exit Function
End If
lstr = LCase(str)
' Check if the string contains any patterns in our black list
For Each s in BlackList
If(IsExceptionList(s,varType)=False) then
If ( InStr (lstr, s) <> 0 ) Then
CheckStringForSQL = true
Exit Function
End If
End If
Next
CheckStringForSQL = false
End Function
CookieExceptionList = Array("""","(",")","!")
Function IsExceptionList(str,varType)
If(varType="cookie") then
For Each item in CookieExceptionList
If(item=str) then
IsExceptionList=True
Exit Function
End If
Next
End If
IsExceptionList=False
End Function
--SO HERE I NEED TO CHECK IF IT IS A FILE INPUT, AND IF SO, NOT RUN THE BELOW--
For Each s in Request.form
If ( CheckStringForSQL(Request.form(s),"form") ) Then
feltext="Fel"
End If
Next

Google Appmaker createItem failing with could not select element

I have a temporary table where I let the user copy the record that needs to be edited. Once the edit is complete, I copy it back.
I am getting an error when I am trying to copy the original record to temporary table for editing. Here's the code I am using
console.log('copyOriginalToTemp ' + tempRecord.ID + ' options ' + JSON.stringify(options));
var myCreateDatasource = app.datasources.RadiosTemp.modes.create;
console.log('# of items in myCreateDatasource ' + myCreateDatasource.items.length);
var draft = myCreateDatasource.item;
draft.BatchId = options.BatchId ;
draft.County = tempRecord.County ;
... // lot of assignments
console.log('About to create item ');
myCreateDatasource.createItem(function(createdRecord) {
console.log('Creating the Item ' + createdRecord._key);
app.datasources.RadiosTemp.query.filters.BatchId._equals = options.BatchId;
.....
});
Error message tells me that newly created item cannot be selected but I have no idea why?. If I change the datasource to Manual Save, I get the same error with no key since it is in Manual save mode.

My datareader has row(s), but I am failing to get the record(s) to textbox from datareader

can anybody tell me where I am doing wrong.I am trying to develop a small site on my own using c#.I am unable to show the record which was fetched from datareader.
{
SqlConnection cone = new SqlConnection("User id=...;Password=;...");
SqlCommand conecmd = new SqlCommand("select bankbalance from bank where bankpassword='" + txtboxbankpassword.Text + "'", cone);
cone.Open();
SqlDataReader drcone = conecmd.ExecuteReader();
if (drcone.HasRows) // says it has row(s) i.e., Hasrows=true
{
while (drcone.Read()) // here its value is false
{
lblremainingbankbalance.Text = drcone["bankbalance"].ToString();
}
int a;
a = Convert.ToInt32(lblremainingbankbalance.Text);
lblmsg.Text = "Transaction successful.Please wait while we redirect you to mypage and your current " + bankstore + " accountbalance is " + a + "";
Response.AddHeader("REFRESH", "5;URL=Mypage.aspx");
txtboxbankpassword.Text = "";
} else {
lblmsg.Text = "Norecord(s)";
}
}
Try to run your query in SQL server and see if it shows some rows because i don't see any errors in code also trim the text of your textbox like this
txtboxbankpassword.Text.Trim()
Also close you connection when you are done with reading rows from datareader.
your case is very strange.. if drcone.HasRowsis true drcone.Read() have to return true... minimum for one time..
Are you debugging the code and add drcone.Read() to quickwatch or have it in your watchlist? Because, then it will run the method Read() before your while loop. Next time when you call Read() (in your while-loop) it will return false..
You get one row, the reader aligns the reader to the first row (in whatchlist), and returns false in your while loop and saying "there are no rows left after this one".
See this link Here for the documentation on this: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx
if you have only a singlerow, the reader "is on position -1".. after drcone.Read() (return true) set the position to 0 (1 and last row).. next time you call drcone.Read() it will return false.. because there are no rows left after this one (reader is on position 0)

How to avoid reassignment of a variable on page load

I'm trying to come up with a function which will allow users to alterate data pressing buttons BACK and NEXT respectively.
I'm using this code for it:
CounterID = IdArray.Length 'array of IDs
determinator = CounterID 'determining which index is active and putting it on the top of array
If Ident = 1 Then ' if button back is pressed
determinator = determinator + 1
If determinator <= CounterID Then
'some actions
End If
Else
determinator = determinator - 1
If determinator >= 0 Then
'some actions
End If
End If
It actually works. But partially. My problem is that whenever a button is presses the value of DETERMINATOR variable is again assigned to the maximum length.
Is there any way to avoid reassignment of this variable and make it happen only once?
You may be able to use a session variable, something like this:
If Session("determinator") <> Nothing Then
determinator = Session("determinator")
else
CounterID = IdArray.Length 'array of IDs
determinator = CounterID
Session("determinator") = determinator
end if
You may want this to be executed depending on IsPostBack.

System.OutOfMemoryException

I have a program written in asp.net with lucene.net. At first I create an index from 28000 documents.
Secondly I'm executing a search, but sometimes there is an error. (I think this error is thrown when there are many results)
The important part of code:
Dim hits As Hits = searcher.Search(query)
Dim results As Integer = hits.Length() 'ergebnisse (größe der hits)
'#####################
'####### RESULTS #####
'#####################
trefferanzahl = results
If (results > 0) Then
Dim i As Integer
Dim h As Integer = results - 1
ReDim array_results(h, 6) 'array zum speichern von den "feldern"
Dim cellX As New TableCell()
For i = 0 To results - 1 Step 1
Dim tmpdoc As Document = hits.Doc(i) ' HERE THE ERROR!
Dim score As Double = hits.Score(i)
MsgBox("2. Docname: " & hits.Doc(i).Get("title"))
array_results(i, 0) = tmpdoc.Get("title")
array_results(i, 0) += tmpdoc.Get("doc_typ")
array_results(i, 1) = tmpdoc.Get("pfad")
array_results(i, 2) = tmpdoc.Get("date_of_create")
array_results(i, 3) = tmpdoc.Get("last_change")
array_results(i, 4) = tmpdoc.Get("id")
array_results(i, 5) = tmpdoc.Get("doc_typ")
array_results(i, 6) = CStr(score)
Next
' Load this data only once.
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
Else
bool_Suchergebnis = False
End If
searcher.Close()
Thanks in advance
A good principle when performing searches accross very large collections is to limit the results that you are processing as soon as possible. I will assume that you are implementing paging in your grid. And lets assume that PageSize is 20.
What you need to do is make sure that you have access to the PageSize and the current PageNo within this method. Then use Linq accross the result set to Take(PageSize) and Skip (PageNo * PageSize). Then you will only have to process 20 records.
Then, you have two options. If you are binding directly to the array, you might be able to get away with empty items, but I am not sure, so you might have to place dummy items into the datasource array in all positions that won't be displayed. Not ideal, but certainly quicker than processing 1000s of Hits.
The second option is to bind only the 20 items to the grid, which will be quick, switch off paging on the grid as it will only show one page and then implement your own paging behaviour as you know the PageSize, and the current PageNo. This will take more work but it will perform a lot faster than the out-of-the-box gridview binding to a large datasource.
And it will help you solve your memory problem.

Resources