Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try lots of way to update into student detail list. I still can't update to the sql server.

What I have tried:

<pre> protected void gvStudent_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(strConn))
                {
                    conn.Open();
                    string query = "UPDATE Student SET Name=@Name,Photo=@Photo,Course=@Course,EmailAddr=@EmailAddr,Password=@Password,Status=@Status,MentorID=@MentorID WHERE StudentID = @id";
                    SqlCommand cmd = new SqlCommand(query, conn);
                    cmd.Parameters.AddWithValue("@Name", (gvStudent.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@Photo", (gvStudent.Rows[e.RowIndex].FindControl("txtPhoto") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@Course", (gvStudent.Rows[e.RowIndex].FindControl("txtCourse") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@EmailAddr", (gvStudent.Rows[e.RowIndex].FindControl("txtEmail") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@Password", (gvStudent.Rows[e.RowIndex].FindControl("txtPassword") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@Status", (gvStudent.Rows[e.RowIndex].FindControl("txtStatus") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@MentorID", (gvStudent.Rows[e.RowIndex].FindControl("txtMentorID") as TextBox).Text.Trim());
                    cmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvStudent.DataKeys[e.RowIndex].Value.ToString()));
                    cmd.ExecuteNonQuery();
                    gvStudent.EditIndex = -1;
                    getStudentDetails();
                    lblSuccessMessage.Text = "Selected Record Updated";
                    lblErrorMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            }
        }
Posted
Updated 29-Jul-18 6:45am

Without your data, it's impossible to tell.
But ... you have your data, and you have a debugger. Combine teh two and your should be able to tell.
So do two things.
1) Change this line:
cmd.ExecuteNonQuery();
To this:
int changed = cmd.ExecuteNonQuery();
and put a breakpoint on it.
When you run your app, use the breakpoint to look at the value you are passing to SQL as the @id parameter. Then single step the line, and check the value of changed - if it's zero, then no rows were changed.

Normally, when an UPDATE "doesn't do anything" without any exception, it's because the WHERE clause matched no rows - so once you've used the debugger to check exactly what you are passing (rather than what you think you are passing) you can examine the DB to find out why it isn't matching.

Sorry, but we can't do any of that for you - we have no access to your data at all!
 
Share this answer
 
Comments
Nicholas Ong 29-Jul-18 10:39am    
How to put breakpoint on it?
Vincent Maverick Durano 29-Jul-18 10:47am    
https://msdn.microsoft.com/en-us/library/y740d9d3.aspx
Nicholas Ong 29-Jul-18 10:50am    
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.

Source Error:


Line 22: <system.codedom>
Line 23: <compilers>
Line 24: <compiler language="c#;cs;csharp" extension=".cs"
Line 25: type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Line 26: warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>

Source File: C:\Users\admin\Desktop\WEBAss\WEB_Assignment\web.config Line: 24

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3056.0
Nicholas Ong 29-Jul-18 11:08am    
@OriginalGriff Can send you my whole folder?
OriginalGriff 29-Jul-18 11:50am    
:laugh: No!
It would be of no use to me anyway - without your DB and suchlike it couldn't run.
Try here:
https://blogs.msdn.microsoft.com/benjaminperkins/2016/08/01/codedom-provider-type-could-not-be-located/
And if that doesn't help try google:
https://www.google.co.uk/search?q=Parser+Error+Message%3A+The+CodeDom+provider+type+%22Microsoft.CodeDom&oq=Parser+Error+Message%3A+The+CodeDom+provider+type+%22Microsoft.CodeDom&aqs=chrome..69i57j69i59&sourceid=chrome&ie=UTF-8
You're supposed to "retrieve" the student before trying to update; in order to prove:

1) The student exists
2) Your "connection string" works
3) The database is online
4) Your query logic works
5) Blah, blah
 
Share this answer
 
v2

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