473,394 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1808
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

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

Similar topics

5
by: Deano | last post by:
Hi, I have a quick problem that I think I know how to solve using DAO but just realised an update query would be more elegant. However I don't have a clue how to implement it. My main table...
0
by: Jerry Tovar | last post by:
I am using .Net 2003. I am trying to build ASP.Net applications, however whenever I build my project and then try to view the webform in a browser, I keep getting the following Parser Error. I...
1
by: rob merritt | last post by:
I have a grideiw that feeds a detailView via 2 AccessDateSources the detail view has and update command that UpdateCommand="UPDATE SET = ? WHERE = " does'nt update since it doesn't...
0
by: BostonSQL | last post by:
The error message is as follows: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific...
7
by: cmpcrand | last post by:
if 2 people are working on the same web site is it possible to be able to work on it Simultaneously so that if i for example was to change something it would change on the other persons screen...
4
by: dancer | last post by:
I get this error if an item in a radiobutton list is not chosen when filling in a form.. I added a RequiredFieldValidator, but I still get the message. Object reference not set to an instance of...
3
by: dancer | last post by:
I am using Framework 1.1.4322. Who can tell me why I'm getting this error? My code follows Compilation Error Description: An error occurred during the compilation of a resource required to...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
1
by: sujitbhattacharya | last post by:
Dear Community I have posted my question earlier also regarding INSERT QUERY My question is like I have two tables in a database One is Employee master ...
3
by: cmrhema | last post by:
Hi, Kindly excuse if I am posting in the wrong place. I am using Visual Studio 2008, .net framework 3.5, asp.net , c# and sql server 2005. I am supposed to pass stored procedures from client...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.