You need to check reader value by using while loop coition till dr.Read() also you need to append the text to current text with database text to append it all the itemcode.
Refer the below sample code for your reference here i used NorthWind Database.
Here i used Label and one Timer control.
On Page Load i sets the Label text also timer is enabled and started on Page Load you can do code as per your code logic.
Form1
C#
NameSpace
using System;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
Code
StringBuilder sb = new StringBuilder();
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
bool direction = false;
if (sb.Length == 0)
sb.Append(lblMarqueText.Text);
if (direction)
{
sb.Insert(0, sb[sb.Length - 1]);
sb.Remove(sb.Length - 1, 1);
}
else
{
sb.Append(sb[0]);
sb.Remove(0, 1);
}
lblMarqueText.Text = sb.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
SetProductMarqueText();
}
private void SetProductMarqueText()
{
string ProductList = "";
string constring = @"Server=.\SQL2005;Database=NorthWind;uid=sa;pwd=pass@123;";
SqlConnection Conn = new SqlConnection(constring);
Conn.Open();
SqlCommand cmd = new SqlCommand("SELECT Top 10 [ProductName] FROM [Products]", Conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ProductList += dr["ProductName"] + ", ";
}
Conn.Close();
lblMarqueText.Text = ProductList;
}
VB.Net
NameSpace
Imports System.Data.SqlClient
Imports System.Text
Code
Private sb As StringBuilder = New StringBuilder()
Public Sub Form1()
InitializeComponent()
End Sub
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim direction As Boolean = False
If sb.Length = 0 Then sb.Append(lblMarqueText.Text)
If direction Then
sb.Insert(0, sb(sb.Length - 1))
sb.Remove(sb.Length - 1, 1)
Else
sb.Append(sb(0))
sb.Remove(0, 1)
End If
lblMarqueText.Text = sb.ToString()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Timer1.Start()
SetProductMarqueText()
End Sub
Private Sub SetProductMarqueText()
Dim ProductList As String = ""
Dim constring As String = "Server=.\SQL2005;Database=NorthWind;uid=sa;pwd=pass@123;"
Dim Conn As SqlConnection = New SqlConnection(constring)
Conn.Open()
Dim cmd As SqlCommand = New SqlCommand("SELECT Top 10 [ProductName] FROM [Products]", Conn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
While dr.Read()
ProductList += dr("ProductName") & ", "
End While
Conn.Close()
lblMarqueText.Text = ProductList
End Sub
Screenshot