473,763 Members | 6,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error updating the employee details!", help

30 New Member
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 1823
ck9663
2,878 Recognized Expert Specialist
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 Recognized Expert Top Contributor
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
1664
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 contains employee records. Each employee *may* have more than one contract i.e if they do more than one job. The contract records are in tblContracts.
0
1133
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 have read somewhere about changing the global.asax and the .Aspx source lines from the Codebehind statement to src. For Example: Codebehind="Global.asax.cs" change to src="Global.asax.cs" and
1
1944
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 recognize the info from the DetailView that it needs to do the update any ideas?
0
967
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 error details and modify your source code appropriately. Compiler Error Message: BC30451: Name 'employee' is not declared. Source Error:
7
1181
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 after a refresh
4
2047
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 an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
3
2252
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 service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30456: 'Text' is not a member of 'System.Web.UI.WebControls.CheckBoxList'.
0
2224
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 ParkingBay CommandField Me Y dropdownlistvalue CommandField You m dropdownlistvalue i have 2 sqldatasource. the other one is for gridview and...
1
969
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 (that is Employee) and other is Salary Master (that is Sal_mast) What I want that the data in employee_Id which is a field in the Table (Employee) should get copied in the Employee_Code Field of the Table (Sal_Mast). Initially I used the Data...
3
5048
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 to wcf service. The WCF service should execute the stored procedure and return the result.
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.