Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Question qs = new Question();
                        string name = Request.QueryString["UserName"];
                        TextBox txtQuestionNo = (TextBox)row.FindControl("Question No");
                        
                        
                        TextBox txtComments = (TextBox)row.FindControl("Comments");
                        //TextBox txtMarks = (TextBox)row.FindControl("Marks");


Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 156:
Line 157:                        //SqlDataAdapter daq = new SqlDataAdapter("update Questionnaire_UserAnswers set Comments='" + txtComments.Text + "', Marks=" + txtMarks.Text + " where Question_ID=" + txtQuestionNo.Text + "UserName='" + name + "'", con);
Line 158:                        SqlDataAdapter daq = new SqlDataAdapter("update Questionnaire_UserAnswers set Comments='" + txtComments.Text + " where Question_ID=" + txtQuestionNo.Text + "UserName='" + name + "'", con);
Line 159:
Line 160:


advance thank for valuable replay
Posted
Updated 28-Nov-11 22:15pm
v2
Comments
2011999 29-Nov-11 4:14am    
not taken values form gridview textbox
uspatel 29-Nov-11 4:15am    
pre tag added.

Take out the space:

C#
TextBox txtQuestionNo = (TextBox)row.FindControl("Question No");
Becomes
C#
TextBox txtQuestionNo = (TextBox)row.FindControl("QuestionNo");
 
Share this answer
 
Comments
thatraja 29-Nov-11 4:25am    
Spot on, 5!
Try adding Cells[index]

C#
TextBox txtQuestionNo = (TextBox)row.Cells[0].FindControl("Question No");

or
C#
TextBox txtQuestionNo = (TextBox)row.Cells[0].FindControl("QuestionNo");


depending on the ID of your textbox control

Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
v3
Comments
2011999 29-Nov-11 4:43am    
not solved my problem still same Error dispaly
[no name] 29-Nov-11 4:54am    
is "row" a gridview or a gridviewrow?
[no name] 29-Nov-11 4:56am    
i'll be posting another solution, i think i got it.
2011999 29-Nov-11 22:56pm    
is Gridviewrows
FROM:
Line 158: SqlDataAdapter daq = new SqlDataAdapter("update Questionnaire_UserAnswers set Comments='" + txtComments.Text + " where Question_ID=" + txtQuestionNo.Text + "UserName='" + name + "'", con);
Line 159:
Line 160:

TO:
Line 158: SqlDataAdapter daq = new SqlDataAdapter("update Questionnaire_UserAnswers set Comments='" + txtComments.Text + "' where Question_ID='" + txtQuestionNo.Text + "' AND UserName='" + name + "'", con);
Line 159:
Line 160:

See code changes above after doing Solution #2

Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
Comments
2011999 29-Nov-11 23:00pm    
not taken Gridviewrow Value
[no name] 30-Nov-11 20:18pm    
what do you mean?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900