472,103 Members | 1,031 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 software developers and data experts.

Error updating the employee details!", help

30
What's wrong?
Compiletor don't show anything, but whet I start program show this error:
"Error updating the employee details!"

Expand|Select|Wrap|Line Numbers
  1.    protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         //416 puslapis
  4.         // Declare objects
  5.         SqlConnection conn;
  6.         SqlCommand comm;
  7.         // Read the connection string from Web.config
  8.         string connectionString =
  9.         ConfigurationManager.ConnectionStrings[
  10.         "Dorknozzle"].ConnectionString;
  11.         // Initialize connection
  12.         conn = new SqlConnection(connectionString);
  13.         // Create command
  14.         comm = new SqlCommand(
  15.         "UPDATE Employees SET Name=@Name,  City=@City " +
  16.         "MobilePhone=@MobilePhone " +
  17.         "WHERE EmployeeID=@EmployeeID", conn);
  18.         // Add command parameters
  19.         comm.Parameters.Add("@Name",
  20.         System.Data.SqlDbType.NVarChar, 50);
  21.         comm.Parameters["@Name"].Value = TextBox1.Text;
  22.  
  23.         comm.Parameters.Add("@City",
  24.         System.Data.SqlDbType.NVarChar, 50);
  25.         comm.Parameters["@City"].Value = TextBox2.Text;
  26.  
  27.         comm.Parameters.Add("@EmployeeID", System.Data.SqlDbType.Int);
  28.         comm.Parameters["@EmployeeID"].Value = TextBox3.Text;
  29.         // Enclose database code in Try-Catch-Finally
  30.         try
  31.         {
  32.             // Open the connection
  33.             conn.Open();
  34.             // Execute the command
  35.             comm.ExecuteNonQuery();
  36.         }
  37.         catch
  38.         {
  39.             // Display error message
  40.             Label1.Text =
  41.             "Error updating the employee details!<br />";
  42.         }
  43.         finally
  44.         {
  45.             // Close the connection
  46.             conn.Close();
  47.         }
  48.         // Refresh the employees list
  49.         //LoadEmployeesList();
  50.     }
  51.  
Jul 19 '08 #1
2 1718
ck9663
2,878 Expert 2GB
Try to get your query by displaying it or showing it in a prompt or messagebox and paste it on your query analyzer and see the actual error.

-- CK
Jul 19 '08 #2
Delerna
1,134 Expert 1GB
You have two statements in your try and if either one fails you get the same error message. I just hope you are not assuming its the update query that is at fault because that is what the error message says.
In fact the problem could also be caused by the

conn.Open();

I suggest moving it outside the try/catch, just to eliminate it as the cause.
Or even into its own try/catch.
Once you have proven its not opening the connection that is causing the error then you need to bug find the update query.

Expand|Select|Wrap|Line Numbers
  1.         conn.Open();
  2.         try
  3.         {
  4.             // Open the connection
  5.  
  6.             // Execute the command
  7.             comm.ExecuteNonQuery();
  8.         }
  9.         catch
  10.         {
  11.             // Display error message
  12.             Label1.Text =
  13.             "Error updating the employee details!<br />";
  14.         }
  15.         finally
  16.         {
  17.             // Close the connection
  18.             conn.Close();
  19.         }
  20.  
It's always a process of isolate and eliminate when debugging errors.
Break it up into smaller or simpler bits and test. If it works add the next bit
Jul 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jerry Tovar | last post: by
1 post views Thread by rob merritt | last post: by
reply views Thread by BostonSQL | last post: by
7 posts views Thread by cmpcrand | last post: by
4 posts views Thread by dancer | last post: by
3 posts views Thread by dancer | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.