Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Actually my marquee is scrolling with "welcome to india"
I have written code for binding ename from database to marquee so it has to scroll with welcome to india
if there is ename in that date both should scroll
else only welcome to india should scroll
so if there is no value inserted its throwing error there is no row at position 0
so if value is inserted itsthrowing error no row at position 1

below is the code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="marquuee.aspx.cs" Inherits="marquuee" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<style>
marquee { font-family:arial; color:#ffffff; font-weight:bold; font-size:54px; text-align:left; height: 50px; padding-top:25px; border: 2px white solid}
.logo { font-family:arial; color:#ffffff; font-size:45px; text-align:left;width:30px; height: 50px; padding-top:2px; border: 2px white solid;
background-color: #000099;
}
.auto-style11 {}
.auto-style12 {
background-color: #000099;
}
</style>
<form id="form1" runat="server">
<div>
<marquee style="font-family:arial; font-size:30px; width: 1282px; background-color: #00FFFF; height: 111px;"red" bgcolor="green" scrollamount="26">
<asp:Literal ID="lt1" runat="server"></asp:Literal> <font color="red">        welcome to ektha</font></marquee>

</div>
</form>
</body>
</html>


using System; // missed a using?
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class marquuee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn1 = new SqlConnection("Data Source=HOME;Initial Catalog=Registration;Integrated Security=True");
SqlDataAdapter da1 = new SqlDataAdapter("select ImageName from imagepath where convert(varchar(20), CurrentDate, 101) = convert(varchar(20), getdate(), 101)", conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "imagepath");
string s1;


s1 = " <font-size: small; font-style: normal;> ";

s1 += ds1.Tables["imagepath"].Rows[0][0].ToString();
s1 += "    ";
s1 += ds1.Tables["imagepath"].Rows[1][0].ToString();
s1 += "    ";

s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();
lt1.Text = s1.ToString();
}
}
Posted
Updated 4-Jul-15 22:17pm
v2

1 solution

Problem is here-
C#
s1 += ds1.Tables["imagepath"].Rows[0][0].ToString();
s1 += "    ";
s1 += ds1.Tables["imagepath"].Rows[1][0].ToString();
s1 += "    ";
 
s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();

You need to put checks on data existance before accesing them.

Try this-
C#
if(ds1.Tables["imagepath"].Rows.Count>0)
{
  s1 += ds1.Tables["imagepath"].Rows[0][0].ToString();
}
s1 += "    ";
if(ds1.Tables["imagepath"].Rows.Count>1)
{
  s1 += ds1.Tables["imagepath"].Rows[1][0].ToString();
}
s1 += "    ";
if(ds1.Tables["imagepath"].Rows.Count>2)
{
  s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();
}


Hope, it helps :)
 
Share this answer
 
Comments
raviram123 6-Jul-15 0:41am    
thanks sir its workings
Suvendu Shekhar Giri 6-Jul-15 1:03am    
Glad to know that it helped.
Please mark it as answer if it helped so that others can get take reference if they come here looking for the same problem.
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900