.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

problem in calculating the marks in online test in asp.net

Posted By: Shweta     Posted Date: January 07, 2011    Points:2   Category :ASP.Net
i have created a function for calculating marks.the function created is as below.
the operation is that i am storing the checked ans in a variable and then its value is compared with the value from database of correct ans.if it is matching then marks is incremented by 1 and so on..but the with the function given below the marks are not incremented..


public int checkans()
{

SqlConnection cn1 = new SqlConnection(@"Data Source=DESKTOP1\SQLEXPRESS;Initial Catalog=TestDatabase;Integrated Security=True");

SqlCommand cmd = new SqlCommand("select ans from online where qno='" + Label1.Text + "'", cn1);

cn1.Open();

dr = cmd.ExecuteReader();

while (dr.Read())
{
if (dr["ans"].ToString() == s)

mark++;

}
return mark;
}

Responses
Author: Sadhuryan             
Posted Date: January 07, 2011     Points: 5   

Where is that variable 's' declared inside the function.
And you haven't passed the variable 's' too.

Author: Shweta             
Posted Date: January 07, 2011     Points: 5   

apart from creating a function for calculating marks which i have posted previously,..there is the button_click() event code as below which includes the parameter s taking the ans selected by the user...


protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
{
s = RadioButton1.Text;
RadioButton1.Checked =false;
}
else if (RadioButton2.Checked == true)
{
s = RadioButton2.Text;
RadioButton2.Checked = false;
}
else if (RadioButton3.Checked == true)
{
s = RadioButton3.Text;
RadioButton3.Checked = false;
}
else if (RadioButton4.Checked == true)
{
s = RadioButton4.Text;
RadioButton4.Checked = false;
}
else
{
MessageBox.Show("PLEASE SELECT AN ANSWER");

}

Response.Write(checkans());
c = Convert.ToInt32(HiddenField1.Value);
c = c + 1;
HiddenField1.Value = c.ToString();
if (c <= ds.Tables["online"].Rows.Count - 1)
{
dr = ds.Tables["online"].Rows[c];
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
RadioButton1.Text = dr[2].ToString();
RadioButton2.Text = dr[3].ToString();
RadioButton3.Text = dr[4].ToString();
RadioButton4.Text = dr[4].ToString();

}
else
{
MessageBox.Show("end of test");

MessageBox.Show("your mark is " + mark.ToString());
Button1.Enabled = false;

}


}

Shweta Agashe
.Net Developer,Global Infobase Solutions.
Author: Sadhuryan             
Posted Date: January 07, 2011     Points: 5   

Try re-writing your code

Response.Write(checkans());


as below

Response.Write(checkans(s));



and change your function definition as

public int checkans(string s)
{
//Your Code will goes here
}




Author: Shweta             
Posted Date: January 07, 2011     Points: 5   

Still its not working...the value only gets incremented for the first tyme...

Shweta Agashe
.Net Developer,Global Infobase Solutions.
Author: Sadhuryan             
Posted Date: January 07, 2011     Points: 5   

May be the value in the RadioButton.Text property and the value inside the database is differ.
Coz, as per your condition, if the condition 'if (dr["ans"].ToString() == s)' is not satisfied, its not going to increment the value. First, verify that.

Reason May be:
1) Misspelled values
2) Different values
3) Additional Spaces
4) Case-Sensitive

Test all the above cases. and try out once again

And try changing your code slightly to identify the error:

while (dr.Read())
{
if (dr["ans"].ToString() == s)
mark++;
}


to

while (dr.Read())
{
if (dr["ans"].ToString() == s)
mark++;
else
MessageBox.Show("Values Mismatch!");
}




Author: Shweta             
Posted Date: January 07, 2011     Points: 5   

as told by u i have put the else block..but the else part is not being executed ..it means that the condition is being satisfied but still the value is not incremented..
i have tried n checked out everything..but still not working...


Shweta Agashe
.Net Developer,Global Infobase Solutions.
Author: Shweta             
Posted Date: January 07, 2011     Points: 5   

plz help me with calculating the marks...bit urgent

Shweta Agashe
.Net Developer,Global Infobase Solutions.
Author: Sadhuryan             
Posted Date: January 08, 2011     Points: 5   

Am not able to find the variable 'mark' declaration and value assigned/initializing part.

if you can provide with your complete logic of this page as attachment. so that, i can guide you properly.

Author: teja             
Posted Date: February 21, 2013     Points: 20   

Hi,for this only if we have 30 questions in exam paper,each question containing 4 options with radio buttons,then how can we write the code for question paper,and how can we calculate the marks,and every question may contain different answers options na,then how it calculate,can you please tell me

Author: Ali             
Posted Date: January 16, 2015     Points: 20   

what is dr here



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend