praveen maurya

praveen maurya

  • NA
  • 0
  • 28.9k

In online exam system next button is not working

Apr 26 2012 12:51 AM
Hello 

I am new in .NET Completed VCC.NET From NIIT I am working on a project which is online examination system
and i have almost done but the the problem arise on showing question when i Press the next button it goes upto only 2 rows pls help me how to display further rows/questions. i am using this code...

using System.Data.SqlClient;

SqlConnection cn = new SqlConnection("Data Source=.;Persist Security Info=False;Initial Catalog=admins;User ID=sa;Password=123456");                      //global declaration
    DataSet ds = new DataSet();              //global declaration
    int i=0;                                          //global declaration


at page load event            


 protected void Page_Load(object sender, EventArgs e)
    {
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select * from ques", cn);
        da.Fill(ds, "ques");
        question.Text = ds.Tables[0].Rows[0][1].ToString();
        objective1.Text = ds.Tables[0].Rows[0][2].ToString();
       objective2.Text = ds.Tables[0].Rows[0][3].ToString();
       objective3.Text = ds.Tables[0].Rows[0][4].ToString();
       objective4.Text = ds.Tables[0].Rows[0][5].ToString();
    }


at next button event

protected void next_Click(object sender, EventArgs e)
    {
        if (i == ds.Tables[0].Rows.Count - 1)
        {
            Response.Redirect("result.aspx");
        }
        else
        {
            i = i + 1;
            question.Text = ds.Tables[0].Rows[i][1].ToString();
           objective1 .Text = ds.Tables[0].Rows[i][2].ToString();
           objective2 .Text = ds.Tables[0].Rows[i][3].ToString();
            objective3 .Text = ds.Tables[0].Rows[i][4].ToString();
            objective4 .Text = ds.Tables[0].Rows[i][5].ToString();
        }


and the database is 

create database admins
use admins
create table ques
(
quesno int identity(1,1),
ques char(100),
ans1 char(50),
ans2 char(50),
ans3 char(50),
ans4 char(50),
rans char(50)
)

insert ques values('what is mouse','input device','output device','hard disk','printer','input device')
insert ques values('what is keybord','input device','output device','hard disk','printer','input device')
insert ques values('what is speaker','input device','output device','hard disk','printer','output device')
insert ques values('what is cpu','input device','processing unit','hard disk','printer','processing unit')
insert ques values('what is ram','input device',' temporay storage','hard disk','printer','temporay storage')





Please help me as soon as possible.
Regards:
Praveen Kuamr






Answers (11)