vb.net data

D

douglas

In the following logic, I code in the loop for with the following code to
execute one more time. The code I am referring is the following:
For A = 0 To ds.Tables(0).Rows.Count - 1
(I would like this code to say or A=max values in dataset.) Thus can you
tell me
what you would do to add this kind of logic)

The outside loop is for the number of rows sel4ected in a dataset that
contains all the data that will be displayed in an excel spreadsheet in the
inner loop.
Dim A As Integer
Dim strZipFileName, strHldHNumber As String
Dim strTemp, strTemp2, strTemp3, x, y, z, strhnumber, strZipFile As String
Dim connetionString As String =
ConfigurationManager.AppSettings.Get("sqlconnect")
im di As New
IO.DirectoryInfo(ConfigurationManager.AppSettings.Get("excel_location"))
Dim aryFi As IO.FileInfo() = di.GetFiles("*.xls")
Dim intCntr As Integer

sqlCnn = New SqlConnection(connectionString)
Dim da As New SqlDataAdapter
Dim ds As New DataSet()
da = New SqlDataAdapter(sqlCmd)
sqlCmd.Connection = New SqlConnection(connectionString)
Try
sqlCnn.Open()

da = New SqlDataAdapter(sqlCmd)
sqlCmd.CommandText =
ConfigurationManager.AppSettings.Get("CommandText")
sqlCmd.CommandType = CommandType.StoredProcedure
da.Fill(ds)
sqlCmd.Dispose()
sqlCnn.Close()


'Initialize our variables
'Check to make sure the directory has at least one record and
the pattern for the reports are named corrected

strHldHNumber =
UCase(Trim(CStr((ds.Tables(0).Rows(0).Item(0))))) ' Position 0

strTemp = ""
strTemp2 = ""
strTemp3 = ""
strZip = ""
strZip2 = ""
strZip3 = ""
strhnumber = ""
Dim IntTotalRows As Integer = ds.Tables(0).Rows.Count
Dim intFileRows As Integer = UBound(aryFi)

For A = 0 To ds.Tables(0).Rows.Count - 1
For intCntr = 0 To UBound(aryFi) Step 1
If Trim(strHldHNumber) = UCase(Mid(aryFi(intCntr).Name,
12, 5)) Then 'hnumber
If (Mid(aryFi(intCntr).Name, 18, 4) = "xxxx") Or
(Mid(aryFi(intCntr).Name, 18, 4) = "XXXX") then
'do something1



Next intCntr

''do something2

next
 
A

Armin Zingler

douglas said:
In the following logic, I code in the loop for with the following code to
execute one more time. The code I am referring is the following:
For A = 0 To ds.Tables(0).Rows.Count - 1
(I would like this code to say or A=max values in dataset.) Thus can you
tell me
what you would do to add this kind of logic)

The outside loop is for the number of rows sel4ected in a dataset that
contains all the data that will be displayed in an excel spreadsheet in the
inner loop.


I'm not quite sure if I understand correctly. To clarify, what are you trying to achieve?
 
D

douglas

"Armin Zingler":

Basically the outside loop contains all the extra data from the database
that is needed. The inside loop contains data that will appear on different
rows in the spreadsheet.

The problem is when I need data for the last row obtained in the database
for the last row that is to appear on a spreadsheet, I am outside of the
loops. This causes the data to not be displayed in the spreadsheet.

For example if there are 875 rows in the dataset and the value for 'A' is
875, it will not fall into the logic "For A = 0 To ds.Tables(0).Rows.Count -
1".
I would like to know how to code
if (For A = 0 To ds.Tables(0).Rows.Count - 1) or A=875 without getting a
..net syntax error. *875 is the number of rows in the dataset. I want the
logic within the loop to be used one more time.

Thanks for your Help!
 
T

Tom Shelton

"Armin Zingler":

Basically the outside loop contains all the extra data from the database
that is needed. The inside loop contains data that will appear on different
rows in the spreadsheet.

The problem is when I need data for the last row obtained in the database
for the last row that is to appear on a spreadsheet, I am outside of the
loops. This causes the data to not be displayed in the spreadsheet.

For example if there are 875 rows in the dataset and the value for 'A' is
875, it will not fall into the logic "For A = 0 To ds.Tables(0).Rows.Count -
1".
I would like to know how to code
if (For A = 0 To ds.Tables(0).Rows.Count - 1) or A=875 without getting a
.net syntax error. *875 is the number of rows in the dataset. I want the
logic within the loop to be used one more time.

Thanks for your Help!

It could be me, but that makes no sense... If there are 875 rows in the table,
then count will return 875. Your loop, would need to be from 0 to 874 to properly
index (zero based index). So:

For A = 0 to ds.Tables(0).Rows.Count - 1
...
Next

would hit every row in the table....
 
A

Armin Zingler

douglas said:
This code does not hit every row in the table. It leaves out the last row.

I still don't understand. I'd say Tom is right. However, you're not even using variable A inside the
loop, so what do you want to use A for?
 
A

Andrew Morton

This code does not hit every row in the table.

Oh yes it does: if you have 10 items in an array then the index goes from 0
to 9. If there are 875 items, the index goes from 0 to 874.

Maybe the last item in the table is blank or does not satisfy your if...then
criteria?

Andrew
 
D

douglas

to keep track if accessed all rows in the table.

I figured out the solution to the problem.


Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top