jefferyajones41
IS-IT--Management
Im trying to get a list of data from a database and assign it to a variable to display as 1 line, all im getting is the last row in the recordset.
<code>
''''''Dimension object variables
dim objConn
dim strConn
dim rs
dim path
dim sqlStr
dim adCmdText
''''''Set this value to nothing to start, otherwise Sample Text will be in our dropdown list
value = ""
''''''Database Connection
strConn="Bakers13-Sysdata"
Set objConn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
objConn.Open strConn
''''''SQL Select Statement
pnum=left(""&ProductNum, 4)
sqlStr = " Select NUTDATA.SHRT_DESC From NUTDATA INNER JOIN crossref ON NUTDATA.ITEM = crossref.CROSSITEM WHERE (((crossref.[item])='4987') AND ((crossref.[typeofinv])='I'))"
'sqlStr ="SELECT crossref.[item], NUTDATA.SHRT_DESC, NUTDATA.ALLERGEN FROM NUTDATA INNER JOIN crossref ON NUTDATA.ITEM = crossref.CROSSITEM WHERE (((crossref.[item])='4987') AND ((crossref.[typeofinv])='I'))"
'sqlStr =" SELECT ITEM, CARBOHYDRT, SIZEGRAM FROM NUTDATA WHERE ITEM='"&pnum& " ' "
''''''Execute
rs.Open sqlStr, objConn', adCmdText
''''''Go to the first record, read the cells until its reaches the end of the set
'if not rs.eof then
'rs.movefirst
'do while not rs.EOF
'value = "INGREDIENTS: " & rs.fields("SHRT_DESC")& vbcr
'rs.MoveNext
'loop
'else
'end if
' This code makes only 3 calls to database, no matter how many rows!
If Not RS.EOF Then arrRS = RS.GetRows()
Set RS = Nothing
If IsArray(arrRS) Then
For i = LBound(arrRS, 2) To UBound(arrRS, 2)
ING = arrRS(0, i)
'ING = arrRS(1, i)
'Response.Write("<p>" & Name & " (" & ID & ")</p>" & vbCrLf)
Value=ING
Next
Erase arrRS
End If
''''''Close the connection
'rs.Close
'Set rs = Nothing
''''''Remove the carriage return from the end of the value
value = Left(Value, Len(Value)-1)
value = RTrim(Value)
</code>
<code>
''''''Dimension object variables
dim objConn
dim strConn
dim rs
dim path
dim sqlStr
dim adCmdText
''''''Set this value to nothing to start, otherwise Sample Text will be in our dropdown list
value = ""
''''''Database Connection
strConn="Bakers13-Sysdata"
Set objConn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
objConn.Open strConn
''''''SQL Select Statement
pnum=left(""&ProductNum, 4)
sqlStr = " Select NUTDATA.SHRT_DESC From NUTDATA INNER JOIN crossref ON NUTDATA.ITEM = crossref.CROSSITEM WHERE (((crossref.[item])='4987') AND ((crossref.[typeofinv])='I'))"
'sqlStr ="SELECT crossref.[item], NUTDATA.SHRT_DESC, NUTDATA.ALLERGEN FROM NUTDATA INNER JOIN crossref ON NUTDATA.ITEM = crossref.CROSSITEM WHERE (((crossref.[item])='4987') AND ((crossref.[typeofinv])='I'))"
'sqlStr =" SELECT ITEM, CARBOHYDRT, SIZEGRAM FROM NUTDATA WHERE ITEM='"&pnum& " ' "
''''''Execute
rs.Open sqlStr, objConn', adCmdText
''''''Go to the first record, read the cells until its reaches the end of the set
'if not rs.eof then
'rs.movefirst
'do while not rs.EOF
'value = "INGREDIENTS: " & rs.fields("SHRT_DESC")& vbcr
'rs.MoveNext
'loop
'else
'end if
' This code makes only 3 calls to database, no matter how many rows!
If Not RS.EOF Then arrRS = RS.GetRows()
Set RS = Nothing
If IsArray(arrRS) Then
For i = LBound(arrRS, 2) To UBound(arrRS, 2)
ING = arrRS(0, i)
'ING = arrRS(1, i)
'Response.Write("<p>" & Name & " (" & ID & ")</p>" & vbCrLf)
Value=ING
Next
Erase arrRS
End If
''''''Close the connection
'rs.Close
'Set rs = Nothing
''''''Remove the carriage return from the end of the value
value = Left(Value, Len(Value)-1)
value = RTrim(Value)
</code>