Hello,
I am battling with something I hope someone here can assist me with.
In Classic ASP, I can loop through a DB Table and display the records with a comma between each value and no comma at the end.
while not rsTags.eof
Tag = rsTags("Tag")
rsTags.movenext
If not rsTags.eof then
%>
"<%=Tag%>",
<%else%>
"<%=Tag%>"<%
end if
wend
%>
There is no substitute in ASP.NET that I have found.
CREATE TABLE [dbo].[Tags](
[TagID] [int] IDENTITY(1,1) NOT NULL,
[TagName] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Tags] PRIMARY KEY CLUSTERED
(
[TagID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[Tags] ON
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (1, N'Dallas')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (2, N'Charlotte')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (3, N'Raleigh')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (4, N'Houston')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (5, N'Washington')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (6, N'New York')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (7, N'Los Angeles')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (8, N'Sydney')
GO
INSERT [dbo].[Tags] ([TagID], [TagName]) VALUES (9, N'Melbourne')
GO
SET IDENTITY_INSERT [dbo].[Tags] OFF
GO
Tags.ashx
This displays all records but with a comma at the end. If I can eliminate the comma at the end, this will be perfect.
Dim cmd As New SqlCommand
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = "select TagID, TagName from Tags"
cmd.Connection = LessonCon
Dim DataAdapter As New SqlDataAdapter
DataAdapter.SelectCommand = cmd
Dim TagList As New DataTable()
DataAdapter.Fill(TagList)
For Each row As DataRow In TagList.Rows
Dim theList As String = ("""" & row.Item("TagName") & """" & ",")
context.Response.Write(theList)
Next
This will display only HALF of the records with NO comma at the end, which is similar to what I used in the Original Classic ASP code. This will work out wonderfully if I can find a way to display all the records.
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim LessonCon As New SqlConnection
Dim LessonCMD As SqlCommand = Nothing
LessonCon = New SqlConnection(ConfigurationManager.ConnectionStrings("Virtual-Learning").ConnectionString)
LessonCon.Open()
Dim getTag As New SqlCommand("select TagID, TagName from Tags", LessonCon)
Dim rsTag As SqlDataReader
rsTag = getTag.ExecuteReader()
context.Response.Write("[")
While rsTag.Read()
Dim strTag As String = rsTag("TagName")
If rsTag.Read() Then
context.Response.Write("""" & strTag & """" & ",")
Else
context.Response.Write("""" & strTag & """")
End If
End While
context.Response.Write("]")
LessonCon.Close()
End Sub
Thanks for any assistance on this issue. Wayne.