J
JenHu
Hi experts,
I wrote a function to use stringbuilder for a fix length text
delimited file for banking stuff.
I received an error on strResult.Insert(141, "".PadLeft(21, " "))
Error: System.ArgumentOutOfRangeException
Message: "Index was out of range. Must be non-negative and
less than the size of the collection.
StackTrace: "at System.Text.StringBuilder.Insert(Int32 index,
String value, Int32 count)
at System.Text.StringBuilder.Insert(Int32 index, String value)
at EPay_Enroller.JenniferFunct.GenerateA(String& strEmpID,
String& strClientAcct, String& strAcctStatus, String&
strAddressFlag, String& strNameFlag)
Any help?
-------------------------------------------------------------------------------------------
Public Function GenerateA(ByRef strEmpID As String, ByRef
strClientAcct As String, ByRef strAcctStatus As String, ByRef
strAddressFlag As String, ByRef strNameFlag As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet
GPConnection = New
SqlConnection("...................................................")
Dim selectCMD As SqlCommand = New SqlCommand("SELECT DDACTNUM,
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " +
strEmpID + "'", GPConnection)
Dim GPDataAdapter As SqlDataAdapter = New SqlDataAdapter
GPDataAdapter.SelectCommand = selectCMD
Dim EfundAcct As String
Dim LName As String
Dim FName As String
Dim MName As String
Dim DOB As String
Dim Loc As String
Try
GPConnection.Open()
Dim DS As DataSet = New DataSet
GPDataAdapter.Fill(DS, "AcctInfoTble")
EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")
LName = DS.Tables("AcctInfoTble").Rows(0)("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(0)("FASTNAME")
'Position 1 2A A
strResult.Insert(0, "A ")
'Position 3 10A Employee Number
strResult.Insert(2, strEmpyID.ToString.PadRight(10, " "))
..........codes
'Position 142 21A Filler
strResult.Insert(141, "".PadLeft(21, " "))
.......more codes
--------------------------------------------------------------------------------------------
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
I wrote a function to use stringbuilder for a fix length text
delimited file for banking stuff.
I received an error on strResult.Insert(141, "".PadLeft(21, " "))
Error: System.ArgumentOutOfRangeException
Message: "Index was out of range. Must be non-negative and
less than the size of the collection.
StackTrace: "at System.Text.StringBuilder.Insert(Int32 index,
String value, Int32 count)
at System.Text.StringBuilder.Insert(Int32 index, String value)
at EPay_Enroller.JenniferFunct.GenerateA(String& strEmpID,
String& strClientAcct, String& strAcctStatus, String&
strAddressFlag, String& strNameFlag)
Any help?
-------------------------------------------------------------------------------------------
Public Function GenerateA(ByRef strEmpID As String, ByRef
strClientAcct As String, ByRef strAcctStatus As String, ByRef
strAddressFlag As String, ByRef strNameFlag As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet
GPConnection = New
SqlConnection("...................................................")
Dim selectCMD As SqlCommand = New SqlCommand("SELECT DDACTNUM,
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " +
strEmpID + "'", GPConnection)
Dim GPDataAdapter As SqlDataAdapter = New SqlDataAdapter
GPDataAdapter.SelectCommand = selectCMD
Dim EfundAcct As String
Dim LName As String
Dim FName As String
Dim MName As String
Dim DOB As String
Dim Loc As String
Try
GPConnection.Open()
Dim DS As DataSet = New DataSet
GPDataAdapter.Fill(DS, "AcctInfoTble")
EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")
LName = DS.Tables("AcctInfoTble").Rows(0)("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(0)("FASTNAME")
'Position 1 2A A
strResult.Insert(0, "A ")
'Position 3 10A Employee Number
strResult.Insert(2, strEmpyID.ToString.PadRight(10, " "))
..........codes
'Position 142 21A Filler
strResult.Insert(141, "".PadLeft(21, " "))
.......more codes
--------------------------------------------------------------------------------------------
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*