TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
priyank gandhi
NA
1
2.1k
use array value in datareader object
Jan 21 2012 2:53 AM
SqlConnection MyConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\apptitude\projects\database\App_Data\Database.mdf;Integrated Security=True;User Instance=True");//this conn is use for update statement
MyConn.Open();
SqlConnection MyConn1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\apptitude\projects\database\App_Data\Database.mdf;Integrated Security=True;User Instance=True");//this conn is use for select statement
MyConn1.Open();
int i,n=5;
String[] month=new String[12]{"January","February","March","April","May","June","July","August","September","Octomber","November","December"};
int day = DateTime.Now.Day;
int mon= DateTime.Now.Month;
mon = mon - 1; //because month array is with 0
Label1.Text = day.ToString();
if (day==21)
{
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = MyConn1;
cmd1.CommandText = "select No_of_times,Dustbin_no from mounthly_data";
SqlDataReader MyReader = cmd1.ExecuteReader();
while (MyReader.Read())
{
String a = MyReader["No_of_times"].ToString();
String b = MyReader["Dustbin_no"].ToString();
SqlCommand cmd = new SqlCommand();
cmd.Connection = MyConn;
cmd.CommandText = "select * from Yearly_data";
SqlDataReader MyReader1 = cmd.ExecuteReader();
while (MyReader1.Read())
{
String tt="";
for(int j=0;j<12;j++) //12 use for mounth
{
if(j!=(mon-1))
{
String mont = MyReader1["('"+month[j]+"')"].ToString();
tt += mont;
}
}
Label1.Text = tt.ToString() ;
}
got error on bold line
i got error like
'January'
System.IndexOutOfRangeException: 'January'
Reply
Answers (
1
)
Reading page count of *broken* .doc (Word 97-2003) file.
Connectivity With Database