I need to make a select call to the DB and bring back the values,
store the column name with the data associated with it.
For example,
Colums and data for table users_table
user_id last_access_dt upd_by upd_dt
Row 1: TESTER 12-February 2010 WILLV 12-February 2010
Row 2: DASANI 12-February 2010 WILLV 12-February 2010
etc. etc.
//Select statement
SELECT * FROM users_table
I do understand the code below populates a one dimensional array. I
just can't seem to find anything that I can wrap my brain around. One
of those days.
//The declaration below is from a function that calls PopulateRS
Function ProcessSuccessfulConnection
Dim arrReturn() As String
ls_sql_String = " SELECT * FROM users_table"
arrReturn = SQLHelper.PopulateRS(ls_sql_String)
array_count = arrReturn.Length
If array_count > 0 Then
For cc = 0 To array_count - 1
ls_data= arrReturn(cc)
**Here I would like to search for specific column names and
its values.**
**Based on the column names and its values, I have to
manipulate some more code.**
Next
End If
End Function
//In SQLHelper
Public Shared Function PopulateRS(ByVal SQL As String) As String()
Dim rsArray(0 To -1) As String
Dim i As Integer = 0
Dim ds3 As System.Data.DataSet = New System.Data.DataSet
Dim conn As System.Data.OracleClient.OracleConnection = Nothing
Dim da3 As System.Data.OracleClient.OracleDataAdapter
Dim ls_error_msg As String = Nothing
Dim ls_error_msg_redirect As String = Nothing
BasePage.OpenConnection(conn)
da3 = New System.Data.OracleClient.OracleDataAdapter(SQL, conn)
da3.Fill(ds3)
If ds3.Tables(0).Rows.Count > 0 Then
'ReDim Preserve rsArray(ds3.Tables(0).Rows.Count)
ReDim Preserve rsArray(ds3.Tables(0).Rows.Count -1)
For Each dr As System.Data.DataRow In ds3.Tables(0).Rows
rsArray(i) = CStr(dr(0).ToString)
'Check if it is the last row
If i < ds3.Tables(0).Rows.Count Then
i = i + 1
Else
Exit For
End If
Next
End If
BasePage.CloseConnection(conn)
PopulateRS = rsArray
End Function
Any help would be much appreciated.
Thanks,
William
Someone appears to have misled you into believing that this is
VB.NET ! This is all VBScript with ASP. Anyone who's ever worked in
ASP would instantly recognize the coding style. I've seen it too often
because it is a common ploy used by rogue software firms to misle
clients who insist on moving to the latest technologies and making
some dough during the so-called "migration phase".
To expand upon your questions:
1. The PopulateRS() function returns a string array containing ONLY
values of the *first column* returned via the SQL script, no matter
how many columns you wanted to retrieve. So you might as well be
asking us how to create a 10-dimensional array and it still would be
no use because the function returns a single dimensional array,
period.
Furthermore, the function does not care about column names. Lastly,
the function does not care about DBNulls. So, unless you have the
professional authority in your firm to invoke another function that
returns something more reasonable or to rewrite your SQLHelper class,
you're in a fix.
I'm sorry to say but the person who wrote the SQLHelper class or
atleast this function has no concept of writing VB.NET code. If that
person happens to be you, then I mean no offense and I would be happy
to show you how it should have been written.
Cerebrus ( you're great, you know?) I agree with all, and hope to see
your way of building the "SqlOracleHelper".
Will, my two cents: if you could try to call a different function, you
should get back a DataTable instead of an array (yes, you culd use two
dimensionals arrays, but why as you could get a container able to keep
data, colums, rows and table informations?), have at least a couple
of overloads of this function : at least one more to use parameters
instead of a sql query with all inside (I am sure it happens to you to
call different queries where you specify something in a where
clause...) , and it could come at hand an overload (better two: with
and without parameters) to call stored procedures (packages) instead
of using inline queryes.
I would also avoid to call basepage in Dal - SqlHelper should be a
class library or in any case a class that should not speak directly
with pages, but with class(es) of Business Logic (Now, this last is a
bit advanced topic for a beginner, so do not mind too much if you do
not follow immediately : simply remember these names and, when you get
a better working SqlHelper and some spear time, have a search for them
and for "three tier" developement).
Thanks again.
On Feb 13, 4:12 pm, Eder Sousa <espnet.sa...@gmail.com> wrote:
> To create a 2 dimensional array:
> Exemplo:
> Dim Array(X, Y) as String
> 'X - Lines
> 'Y- Rows
>
> On Sat, Feb 13, 2010 at 5:10 PM, Charles A. Lopez
> <charlesalo...@gmail.com>wrote:
>
>
>
>
>
> > Interesting. What exactly are you trying to do?
>
> > You state you want to create a 2 dimensional array. Then what?
>
>
> > Registered Microsoft Partner
>
> > New York City, NY
>
> > I'm running on Windows 7 Build 7100
>
> > Quality Software Works
>
> --
> Eder Sousa
> Technology Information
> espnet.so...@gmail.com
> eespn...@hotmail.com
> esp...@uol.com.br- Hide quoted text -
>
> - Show quoted text -
Public Shared Function PopulateRS(ByVal SQL As String) As DataTable
Dim dt As New System.Data.DataTable
Dim conn As System.Data.OracleClient.OracleConnection = Nothing
Dim da3 As System.Data.OracleClient.OracleDataAdapter
Dim ls_error_msg As String = Nothing
Dim ls_error_msg_redirect As String = Nothing
BasePage.OpenConnection(conn)
da3 = New System.Data.OracleClient.OracleDataAdapter(SQL, conn)
da3.Fill(dt)
BasePage.CloseConnection(conn)
Return dt
End Function
you could then play with datable this way:
Dim dt As DataTable = sqlHelper.PopulateRS("select * from testdb")
'print all clomns names
For Each cl As DataColumn In dt.Columns
Response.Write(cl.ColumnName)
Next
'print all values of each row
For Each dr As DataRow In dt.Rows
For Each cl As DataColumn In dt.Columns
Response.Write(dr(cl).ToString())
Next
Next
2010/2/18 Will <william...@tc.gc.ca>:
William.
On Feb 20, 9:09 pm, Cesare Imperiali <cesare.imperi...@gmail.com>
wrote:
> 2010/2/18 Will <william.vikt...@tc.gc.ca>:
> >> - Show quoted text -- Hide quoted text -