i have little problem i am designing a online exam system using asp and c# with sql server backend approximately i have completed my all project but in last when user select a user it store in a table name as "uans" but not in correct format
i am giving the code please help me in this and suggest me how to calculate marks and display the result.
pls help me as soon as possible
at page load
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;
ques.Text = ds.Tables[0].Rows[0]["ques"].ToString();
ans1.Text = ds.Tables[0].Rows[1]["ans1"].ToString();
ans2.Text = ds.Tables[0].Rows[2]["ans2"].ToString();
ans3.Text = ds.Tables[0].Rows[3]["ans3"].ToString();
ans4.Text = ds.Tables[0].Rows[4]["ans4"].ToString();
}
at next question button click event result will display after last question
protected void Button1_Click(object sender, EventArgs e)
{
cn.Open();
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)
{
ques.Text = ds.Tables[0].Rows[i]["ques"].ToString();
ans1.Text = ds.Tables[0].Rows[i]["ans1"].ToString();
ans2.Text = ds.Tables[0].Rows[i]["ans2"].ToString();
ans3.Text = ds.Tables[0].Rows[i]["ans3"].ToString();
ans4.Text = ds.Tables[0].Rows[i]["ans4"].ToString();
}
else
{
Response.Redirect("result.aspx");
}
SqlCommand cmd1 = new SqlCommand("insert uans values(@ans)", cn);
if (ans1.Checked)
{
cmd1.Parameters.Add("@ans", ans1.Text);
cmd1.ExecuteNonQuery();
if (ans2.Checked)
{
//SqlCommand cmd2 = new SqlCommand("insert uans values(@ans)", cn);
cmd1.Parameters.Add("@ans", ans2.Text);
cmd1.ExecuteNonQuery();
if (ans3.Checked)
{
// SqlCommand cmd3 = new SqlCommand("insert uans values(@ans)", cn);
cmd1.Parameters.Add("@ans", ans3.Text);
cmd1.ExecuteNonQuery();
}
}
}
else
{
// SqlCommand cmd4 = new SqlCommand("insert uans values(@ans)", cn);
cmd1.Parameters.Add("@ans", ans4.Text);
cmd1.ExecuteNonQuery();
}
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')
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')
create table uans
(
ans char(30)
)

praveen mauryaPosted Apr 28, 2012, 3:38 PM
hello is there no one to help me out
how sad.....
praveen mauryaPosted Apr 27, 2012, 5:46 AM
its my pleasure tha tyou respond my question but i am a begineer and this is my first web project so i am unable to understand your advanced language please help me in e=a easier language. thank you
SenthilkumarPosted Apr 27, 2012, 12:13 AM
You need to store the values temporarily in the DataSet or some other objects (may be custom objects), because you can't insert and update for every question. When you have the option to move front and back, you can't store every time in the database table.
I suggest you to store in the DataTable or DataSet and need to update with in the DataTable or DataSet and when click on the submit of the last question you need to iterate and store into the database table.
It may be
S.No UserId QuestionID Answer