473,551 Members | 2,676 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 1813
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
1659
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...
0
1113
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:...
1
1934
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
958
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
1163
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
2031
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...
3
2242
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:...
0
2213
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 ...
1
962
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)...
3
5038
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
7565
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...
0
7492
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...
0
8002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5130
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...
0
3534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1981
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
1
1097
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
804
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...

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.