FilePut returns unhandled exception of type 'System.ArgumentException' - visual-studio-2013

I am writing in Visual Basic on Visual Studio 2013.
I have defined the Customer record structure in a module. I am trying to save to a fixed length record. However, when I try and save it comes back highlighting FilePut with the error message:
"An unhandled exception of type 'System.ArgumentException' occurred in
Microsoft.VisualBasic.dll".
My code for the subroutine is below:
'Open customer file to find what ID to use
FileOpen("1", "CustomerRecord.dat", OpenMode.Random, OpenAccess.ReadWrite)
'Find length of customer file
Dim RecordLength As Integer = Len(Customer)
'Populate customer ID with algorithm to find unique ID to use (Last ID used + 1)
txt_CustomerID.Text = Str(LOF(1) / RecordLength + 1)
'Find record number to write
Dim RecordToWrite As Integer = (LOF(1) / RecordLength + 1)
'Populate all the customer variables with the corresponding
'textbox information
Customer.CusID = Int(txt_CustomerID.Text)
Customer.Title = cmb_Title.Text
Customer.Forename = txt_Forename.Text
Customer.Surname = txt_Surname.Text
Customer.Postcode = txt_Postcode.Text
Customer.NameNo = txt_HouseName.Text
Customer.Town = txt_Town.Text
Customer.DOB = txt_DOB.Text
Customer.TelNo = txt_TelNo.Text
Customer.Email = txt_Email.Text
FilePut("1", Customer, RecordToWrite)
FileClose(1)
How would I solve this problem?

Related

Using Find to find a user property in Outlook/Redemption

I'm trying to return a single calendaritem from Outlook from our C# windows desktop application. It keeps returning this error:
Redemption.RDOItems
Assertion failed: Number of fields == 1.
I use similar code in an Outlook addin I created and it works fine. The main difference is the filterprefix.
In the AddIn I use:
string filterprefix = "[" + OurCustomProperty.OurItemId + "] = '";
var filter1 = filterprefix + parentItem.NeedlesId + "'";
var findItem = folder.Items.Find(filter1);
but this code does not work from our desktop app.
Here is the code from the desktop App which is returning the error:
The appointment.Id contains a valid value which we set when we create the item.
string Filterprefix = "#SQL="+"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/OurCustomProperty.OurItemId/0x0000001f = '";
RDOSession rdoSession = new RDOSession();
rdoSession.Logon("", "", false, false, null, false);
RDOFolder folderRDO = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);
var filter1 = filterprefix + appointment.Id + "'";
string ls_find = Filterprefix + appointment.Id + "'" ;
var findItem = folderRDO.Items.Find(ls_find);
I've tried several variations of the syntax but can't seem to get it right.
I also tried using Sort then Restrict but no luck with that either.
Thanks, Rick
RDOItems.Find takes a SQL statement, please do not use the #SQL= prefix - it is OOM specific. Also do not forget to doublequote the DASL property name:
"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/OurCustomProperty.OurItemId/0x0000001f" = '<some value>'

Why is my dataveiw filter crashing

i have a dataview from a data table i am trying to filter to see if there are duplicate values for a manufacture, Type and Serial number but i am getting an error
string strFilter = "Manufacture = " + strMake + " and Type = " + strModel + " and Serial Number = " + strSn;
strfilter = "Manufacture = ford 150 and Type = Raptor and Serial Number = 9999"
dv.RowFilter = strFilter;
this it the error i am getting
An unhandled exception of type 'System.Data.SyntaxErrorException' occurred in System.Data.dll
Additional information: Syntax error: Missing operand after 'Number' operator
You need single quotes for strings.Write serial number in brackets like [Serial number] if that is the name of your column.
For one you are missing a semi colon here.
strfilter = "Manufacture = ford 150 and Type = Raptor and Serial Number = 9999" <---------
:)

Access 2010 - Run-time error 3022

I'm trying to add records to an exisiting table called "Topics" (section as of "For Each SelectedTopic In SelectedTopicsCtl.ItemsSelected" in the code below).
When executing the code i always get "Run-time error '3022': The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. So it goes wrong at the creation of the Autonumber in the field "ID" (= the only field that is indexed - no duplicates).
When debugging, line "TopicRecord.Update" in the code below is highlighted.
I have read several posts on this topic on this forum and on other forums but still cannot get this to work - i must be overlooking something....
Private Sub Copy_Click()
Dim JournalEntrySourceRecord, JournalEntryDestinationRecord, TopicRecord As Recordset
Dim JournalEntryToCopyFromCtl, JournalEntryToCopyToCtl, JournalEntryDateCreatedCtl, SelectedTopicsCtl As Control
Dim Counter, intI As Integer
Dim SelectedTopic, varItm As Variant
Set JournalEntryToCopyFromCtl = Forms![Copy Journal Entry]!JournalEntryToCopyFrom
Set JournalEntryToCopyToCtl = Forms![Copy Journal Entry]!JournalEntryToCopyTo
Set JournalEntryDateCreatedCtl = Forms![Copy Journal Entry]!JournalEntryDateCreated
Set JournalEntrySourceRecord = CurrentDb.OpenRecordset("Select * from JournalEntries where ID=" & JournalEntryToCopyFromCtl.Value)
Set JournalEntryDestinationRecord = CurrentDb.OpenRecordset("Select * from JournalEntries where ID=" & JournalEntryToCopyToCtl.Value)
Set SelectedTopicsCtl = Forms![Copy Journal Entry]!TopicsToCopy
Set TopicRecord = CurrentDb.OpenRecordset("Topics", dbOpenDynaset, dbSeeChanges)
With JournalEntryDestinationRecord
.Edit
.Fields("InitiativeID") = JournalEntrySourceRecord.Fields("InitiativeID")
.Fields("DateCreated") = JournalEntryDateCreatedCtl.Value
.Fields("Comment") = JournalEntrySourceRecord.Fields("Comment")
.Fields("Active") = "True"
.Fields("InternalOnly") = JournalEntrySourceRecord.Fields("InternalOnly")
.Fields("Confidential") = JournalEntrySourceRecord.Fields("Confidential")
.Update
.Close
End With
JournalEntrySourceRecord.Close
Set JournalEntrySourceRecord = Nothing
Set JournalEntryDestinationRecord = Nothing
For Each SelectedTopic In SelectedTopicsCtl.ItemsSelected
TopicRecord.AddNew
For Counter = 3 To SelectedTopicsCtl.ColumnCount - 1
TopicRecord.Fields(Counter) = SelectedTopicsCtl.Column(Counter, SelectedTopic)
Next Counter
TopicRecord.Fields("JournalEntryID") = JournalEntryToCopyToCtl.Value
TopicRecord.Fields("DateCreated") = JournalEntryDateCreatedCtl.Value
TopicRecord.Update
Next SelectedTopic
TopicRecord.Close
Set TopicRecord = Nothing
End Sub
First, your Dims won't work as you expect. Use:
Dim JournalEntrySourceRecord As Recordset
Dim JournalEntryDestinationRecord As Recordset
Dim TopicRecord As Recordset
Second, it looks like you get your ID included here:
TopicRecord.Fields(Counter)
or Topic is a query that includes it somehow. Try to specify the fields specifically and/or debug like this:
For Counter = 3 To SelectedTopicsCtl.ColumnCount - 1
TopicRecord.Fields(Counter).Value = SelectedTopicsCtl.Column(Counter, SelectedTopic)
Debug.Print Counter, TopicRecord.Fields(Counter).Name
Next Counter

CT_FETCH error in PowerBuilder Program

I'm still learning PowerBuilder and trying to get familiar with it. I'm receiving the following error when I try to run a program against a specific document in my database:
ct_fetch(): user api layer: internal common library error: The bind of result set item 4 resulted in an overflow. ErrCode: 2.
What does this error mean? What is item 4? This is only when I run this program against a specific document in my database, any other document works fine. Please see code below:
string s_doc_nmbr, s_doc_type, s_pvds_doc_status, s_sql
long l_rtn, l_current_fl, l_apld_fl, l_obj_id
integer l_pvds_obj_id, i_count
IF cbx_1.checked = True THEN
SELECT dsk_obj.obj_usr_num,
dsk_obj.obj_type,
preaward_validation_doc_status.doc_status,
preaward_validation_doc_status.obj_id
INTO :s_doc_nmbr, :s_doc_type, :s_pvds_doc_status, :l_pvds_obj_id
FROM dbo.dsk_obj dsk_obj,
preaward_validation_doc_status
WHERE dsk_obj.obj_id = :gx_l_doc_obj_id
AND preaward_validation_doc_status.obj_id = dsk_obj.obj_id
using SQLCA;
l_rtn = sqlca.uf_sqlerrcheck("w_pdutl095_main", "ue_run_script", TRUE)
IF l_rtn = -1 THEN
RETURN -1
END IF
//check to see if document (via obj_id) exists in the preaward_validation_doc_status table.
SELECT count(*)
into :i_count
FROM preaward_validation_doc_status
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF i_count = 0 THEN
//document doesn't exist
// messagebox("Update Preaward Validation Doc Status", + gx_s_doc_nmbr + ' does not exist in the Preaward Validation Document Status table.', Stopsign!)
//MC - 070815-0030-MC Updating code to insert row into preaward_validation_doc_status if row doesn't already exist
// s_sql = "insert into preaward_validation_doc_status(obj_id, doc_status) values (:gx_l_doc_obj_id, 'SUCCESS') "
INSERT INTO preaward_validation_doc_status(obj_id, doc_status)
VALUES (:gx_l_doc_obj_id, 'SUCCESS')
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number ' + gx_s_doc_nmbr + ' has been inserted and marked as SUCCESS for PreAward Validation.')
return 1
Else
//Update document status in the preaward_validation_doc_status table to SUCCESS
Update preaward_validation_doc_status
Set doc_status = 'SUCCESS'
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number '+ gx_s_doc_nmbr + ' has been marked as SUCCESS for PreAward Validation.')
End IF
update crt_script
set alt_1 = 'Acknowledged' where
ticket_nmbr = :gx_s_ticket_nmbr and
alt_2 = 'Running' and
doc_nmbr = :gx_s_doc_nmbr
USING SQLCA;
Return 1
ElseIF cbx_1.checked = False THEN
messagebox("Update Preaward Validation Doc Status", 'The acknowledgment checkbox must be selected for the script to run successfully. The script will now exit. Please relaunch the script and try again . ', Stopsign!)
Return -1
End IF
Save yourself a ton of headaches and use datawindows... You'd reduce that entire script to about 10 lines of code.
Paul Horan gave you good advice. This would be simple using DataWindows or DataStores. Terry Voth is on the right track for your problem.
In your code, Variable l_pvds_obj_id needs to be the same type as gx_l_doc_obj_id because if you get a result, it will always be equal to it. From the apparent naming scheme it was intended to be long. This is the kind of stuff we look for in peer reviews.
A few other things:
Most of the time you want SQLCode not SQLDbCode but you didn't say what database you're using.
After you UPDATE crt_script you need to check the result.
I don't see COMMIT or ROLLBACK. Autocommit isn't suitable when you need to update multiple tables.
You aren't using most of the values from the first SELECT. Perhaps you've simplified your code for posting or troubleshooting.

Can't force LINQ evaluation

I'm trying to get a record and store it for later use if an error occurs on the page.
This code is used on Create/Edit. So I'm getting values from a View Model and mapping to the db entity:
Dim objExistingSupplier As SUPPLIER = db.SUPPLIER.Single(Function(e) e.SUPPLIER_ID = Supplier.SUPPLIER_ID)
objPermStaffAction = objExistingSupplier
objSupplier = Mapper.Map(Of SupplierViewModel, SUPPLIER)(Supplier, objExistingSupplier)
From what I understand, the .Single should force evaluation. However, after the mapping occurs properties are lost/changed in the objPermStaffAction object. Can someone explain what I'm doing wrong?
Here is the whole function:
Private Function SaveSupplier(Supplier As SupplierViewModel) As ActionResult
Dim objSupplier, objPermStaffAction As SUPPLIER
If Supplier.SUPPLIER_ID = 0 Then
objSupplier = Mapper.Map(Of SupplierViewModel, SUPPLIER)(Supplier)
Else
Dim objExistingSupplier As SUPPLIER = db.SUPPLIER.Single(Function(e) e.SUPPLIER_ID = Supplier.SUPPLIER_ID)
objPermStaffAction = objExistingSupplier
objSupplier = Mapper.Map(Of SupplierViewModel, SUPPLIER)(Supplier, objExistingSupplier)
End If
If ModelState.IsValid Then
If Supplier.SUPPLIER_ID = 0 Then
objSupplier.CREATED_BY = Session("AppUserID")
db.SUPPLIER.Add(objSupplier)
Else
objSupplier.UPDATED_BY = Session("AppUserID")
UpdateModel(objSupplier)
End If
Try
db.SaveChanges()
Return RedirectToAction("Index")
Catch ex As Exception
If InStr(ex.InnerException.InnerException.Message, "PRSNL.SUPPLIER_UK") > 0 Then
ModelState.AddModelError("SUPPLIER_CODE", "Supplier Code already exists. Please choose another.")
End If
End Try
End If
'This will run if an error occured
If Supplier.SUPPLIER_ID > 0 Then
Supplier = Mapper.Map(Of SupplierViewModel)(objPermStaffAction)
End If
ViewBag.YNList = Common.GetYNList
Return View(Supplier)
End Function
SupplierViewModel is reference type. So objPermStaffAction refer to the same object which is getting updated after mapping.
Why do you need original (not mapped) object?

Resources