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
praveen maurya
NA
0
29.1k
Display result in online examsystem
May 6 2012 11:14 PM
hello there in online exam project when i am dispalying result the condition checking is showing problm it always shows else part
my all coading is below
reply as soon as possible
code for question page
SqlConnection cn = new SqlConnection("Data Source=.;Persist Security Info=False;Initial Catalog=admins;User ID=sa;Password=123456");
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from ques", cn);
DataSet ds = new DataSet();
da.Fill(ds, "ques");
ViewState["i"] = 0;
Label2.Text = ds.Tables[0].Rows[0]["quesno"].ToString();
Label1.Text = ds.Tables[0].Rows[0]["ques"].ToString();
RadioButton1.Text = ds.Tables[0].Rows[0]["ans1"].ToString();
RadioButton2.Text = ds.Tables[0].Rows[0]["ans2"].ToString();
RadioButton3.Text = ds.Tables[0].Rows[0]["ans3"].ToString();
RadioButton4.Text = ds.Tables[0].Rows[0]["ans4"].ToString();
cn.Close();
}
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("update ques set ans=@ans where quesno=@quesno", cn);
cn.Open();
cmd.Parameters.Add(new SqlParameter("@ans", RadioButton1.Text));
cmd.Parameters.Add(new SqlParameter("@quesno", Label2.Text));
cmd.ExecuteNonQuery();
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("update ques set ans=@ans where quesno=@quesno", cn);
cn.Open();
cmd.Parameters.Add(new SqlParameter("@ans", RadioButton2.Text));
cmd.Parameters.Add(new SqlParameter("@quesno", Label2.Text));
cmd.ExecuteNonQuery();
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("update ques set ans=@ans where quesno=@quesno", cn);
cn.Open();
cmd.Parameters.Add(new SqlParameter("@ans", RadioButton3.Text));
cmd.Parameters.Add(new SqlParameter("@quesno", Label2.Text));
cmd.ExecuteNonQuery();
}
protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("update ques set ans=@ans where quesno=@quesno", cn);
cn.Open();
cmd.Parameters.Add(new SqlParameter("@ans", RadioButton4.Text));
cmd.Parameters.Add(new SqlParameter("@quesno", Label2.Text));
cmd.ExecuteNonQuery();
}
protected void Button3_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(ViewState["i"]) + 1;
SqlDataAdapter da = new SqlDataAdapter("select * from ques", cn);
da.Fill(ds, "ques");
ViewState["i"] = (int)ViewState["i"] + 1;
if (ds != null && (int)ViewState["i"] < ds.Tables[0].Rows.Count)
{
Label2.Text = ds.Tables[0].Rows[i]["quesno"].ToString();
Label1.Text = ds.Tables[0].Rows[i]["ques"].ToString();
RadioButton1.Text = ds.Tables[0].Rows[i]["ans1"].ToString();
RadioButton2.Text = ds.Tables[0].Rows[i]["ans2"].ToString();
RadioButton3.Text = ds.Tables[0].Rows[i]["ans3"].ToString();
RadioButton4.Text = ds.Tables[0].Rows[i]["ans4"].ToString();
}
else
{
Response.Redirect("result.aspx");
}
code for result page
SqlConnection cn = new SqlConnection("Data Source=.; Initial Catalog=admins; User ID=sa; Password=123456");
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from ques", cn);
da.Fill(ds, "ques");
string a = ds.Tables[0].Rows[0][6].ToString();
string b = ds.Tables[0].Rows[0][7].ToString();
if (a == b)
{
int m = 1;
marks.Text = m.ToString();
}
else
{
marks.Text = "no";
}
database code
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')
insert ques values('what is dam','input/p device',' dtemporay storage','dhard disk','dprinter','dtemporay storage')
insert ques values('what is qram','qinput device',' qtemporay storage','qhard disk','qprinter','qtemporay storage')
insert ques values('what is dam','input/p device',' dtemporay storage','dhard disk','dprinter','dtemporay storage')
insert ques values('what is nam','input/p device',' dtemporay storage','dhard disk','dprinter','dtemporay storage')
insert ques values('what is bam','input/p device',' dtemporay storage','dhard disk','dprinter','dtemporay storage')
alter table ques
add ans char(30)
Reply
Answers (
2
)
ExtNetDataDataContext as type or namespace not found
Progress Bar