473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

StringBuilder and dataset

Hi experts,

I received a sample from bank for the header record in the output file
(attached at the bottom).

I want to use same method to have a stringbuilder to arrange the fix
length positions, and the fields will be retrieved from database and
put into the dataset. But I am familiar at how to use dataset and
put into .insert stringbuilder. Here is the code that I am working
on (the function should return 1 string line at a time. The loop of
reading rows will be controled in main form): Can someone show me
how to retrieve a column, say LastName and put into
strResult.Insert()??? Thanks.

Imports System.Data.SqlClient
Module Module1
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 GPDataAdapter As New SqlDataAdapter("SELECT
LASTNAME,FRSTNAME,MIDLNAME,PHONE1,BRTHDATE FROM UPR00102 where
EmployID="+strEmpID,GPConnection)
Try
GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
'position 1 20A
strResult.Insert ?????????????????

Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
GPConnection.Dispose()
End Try
Return strResult.ToString
End Function
End Module
-------------------------------------------------------------------------------------
Module GenerateFile

Public Function GenerateFH(ByRef strCompanyName As String, ByRef
strTopCorp As String, ByRef strBatchNum As String, ByRef dtFileDate
As Date)
Dim strResult As New System.Text.StringBuilder
strResult.Capacity = 731
'Position 1 2A FH
strResult.Insert(0, "FH")
'Position 3 10A Header Date
strResult.Insert(2, dtFileDate.Date.Year & "/" &
dtFileDate.Date.Month.ToString.PadLeft(2, "0") & "/" &
dtFileDate.Date.Day.ToString.PadLeft(2, "0"))
'Position 13 8A Header Time
strResult.Insert(12,
dtFileDate.TimeOfDay.Hours.ToString.PadLeft(2, "0") & ":" &
dtFileDate.TimeOfDay.Minutes.ToString.PadLeft(2, "0") & ":" &
dtFileDate.TimeOfDay.Seconds.ToString.PadLeft(2, "0"))
'Position 21 10A Transfer File Version
strResult.Insert(20, "4.0".PadRight(10, " "))
'Position 31 10A Product Type
strResult.Insert(30, "EFUNDS".PadRight(10, " "))
.............
Return strResult.ToString
End Function
End Module
---------------------------------------------------------------------------

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
1 3422
JenHu,

In this case I would not use the stringbuilder.

This is one of the cases where in my opinion the classic VB Mid is the
simplest way to go.

http://msdn.microsoft.com/library/de...l/vafctMid.asp

Cor
"JenHu" <je**********@hotmail-dot-com.no-spam.invalid>
Hi experts,

I received a sample from bank for the header record in the output file
(attached at the bottom).

I want to use same method to have a stringbuilder to arrange the fix
length positions, and the fields will be retrieved from database and
put into the dataset. But I am familiar at how to use dataset and
put into .insert stringbuilder. Here is the code that I am working
on (the function should return 1 string line at a time. The loop of
reading rows will be controled in main form): Can someone show me
how to retrieve a column, say LastName and put into
strResult.Insert()??? Thanks.

Imports System.Data.SqlClient
Module Module1
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 GPDataAdapter As New SqlDataAdapter("SELECT
LASTNAME,FRSTNAME,MIDLNAME,PHONE1,BRTHDATE FROM UPR00102 where
EmployID="+strEmpID,GPConnection)
Try
GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
'position 1 20A
strResult.Insert ?????????????????

Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
GPConnection.Dispose()
End Try
Return strResult.ToString
End Function
End Module
-------------------------------------------------------------------------------------
Module GenerateFile

Public Function GenerateFH(ByRef strCompanyName As String, ByRef
strTopCorp As String, ByRef strBatchNum As String, ByRef dtFileDate
As Date)
Dim strResult As New System.Text.StringBuilder
strResult.Capacity = 731
'Position 1 2A FH
strResult.Insert(0, "FH")
'Position 3 10A Header Date
strResult.Insert(2, dtFileDate.Date.Year & "/" &
dtFileDate.Date.Month.ToString.PadLeft(2, "0") & "/" &
dtFileDate.Date.Day.ToString.PadLeft(2, "0"))
'Position 13 8A Header Time
strResult.Insert(12,
dtFileDate.TimeOfDay.Hours.ToString.PadLeft(2, "0") & ":" &
dtFileDate.TimeOfDay.Minutes.ToString.PadLeft(2, "0") & ":" &
dtFileDate.TimeOfDay.Seconds.ToString.PadLeft(2, "0"))
'Position 21 10A Transfer File Version
strResult.Insert(20, "4.0".PadRight(10, " "))
'Position 31 10A Product Type
strResult.Insert(30, "EFUNDS".PadRight(10, " "))
.............
Return strResult.ToString
End Function
End Module
---------------------------------------------------------------------------

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
2
by: Ray Stevens | last post by:
I am loading a pipe-delimited string from a DataSet into StringBuilder, such as 00P|23423||98723 (etc.). For some reason the pipe character is displaying in the debugger as "o" with two small dots...
4
by: I am Sam | last post by:
I don't know why but in my stringbuilder. The string is cut off I set the size but it is still missing part of the string. Here is the codebehind: public System.Text.StringBuilder...
0
by: I am Sam | last post by:
Ok I don't know what is the problem with my code But I am trying to build a newsletter that gathers parameters from 3 textbox controls and a Listbox control. The form then queries the event table...
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
23
by: J Jones | last post by:
I need to plug values into a condition like: ((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E > 59) And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19 And F >...
1
by: JenHu | last post by:
Hi experts, I am using stringbuilder in a funtion for a fix length text delimited file for banking stuff. I received an error on strResult.Insert(141, "".PadLeft(21, " ")) Error:...
4
by: Rich | last post by:
I understand that the stringbuilder object can create a string of text much more quickly/efficiently than a string object. I am just checking - if I have a textfile with say 1000 rows of data -...
26
by: Hardy Wang | last post by:
Hi all, I know it is better to handle large string with a StringBuilder, but how does StringBuilder class improve the performance in the background? Thanks! -- WWW:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.