473,320 Members | 1,857 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,320 software developers and data experts.

Getting the error for inseting the value

Hi friends i have a probelm i am try to pass the value to the employeeid parameter but getting th error please help me how i can do this i am getting the error here is my code
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using System.Data.SqlTypes;
  13. using System.DirectoryServices;
  14.  
  15. namespace Accomplishments
  16. {
  17.     /// <summary>
  18.     /// Summary description for Accomplishment.
  19.     /// </summary>
  20.     public class Accomplishment : System.Web.UI.Page
  21.     {
  22.         protected System.Web.UI.WebControls.TextBox txtFirstName;
  23.         protected System.Web.UI.WebControls.TextBox txtLastName;
  24.         protected System.Web.UI.WebControls.TextBox txtdatecreated;
  25.         protected System.Web.UI.WebControls.TextBox txtProject;
  26.         protected System.Web.UI.WebControls.TextBox txtdescription;
  27.         protected System.Web.UI.WebControls.TextBox Login;
  28.         protected System.Web.UI.WebControls.TextBox txtLogin;
  29.         protected System.Web.UI.WebControls.DropDownList drpProject;
  30.         protected System.Web.UI.WebControls.TextBox txtdept;
  31.         protected System.Web.UI.WebControls.RequiredFieldValidator Project;
  32.         protected System.Web.UI.WebControls.DropDownList drpMonth;
  33.         protected System.Web.UI.WebControls.Button cmdSubmit;
  34.  
  35.         private void Page_Load(object sender, System.EventArgs e)
  36.         {
  37.             txtdatecreated.Text = DateTime.Now.ToShortDateString();
  38.             // Put user code to initialize the page here
  39.             if(Session["Login"].ToString() != null)
  40.             {
  41.                 this.txtLogin.Text=Session["Login"].ToString();
  42.             }
  43.  
  44.             if(Session["fn"].ToString() != null)
  45.             {
  46.                 this.txtFirstName.Text=Session["fn"].ToString();
  47.             }
  48.  
  49.             if(Session["sn"].ToString() != null)
  50.             {
  51.                 this.txtLastName.Text=Session["sn"].ToString();
  52.             }
  53.  
  54.             if(Session["department"].ToString() != null)
  55.             {
  56.                 this.txtdept.Text=Session["department"].ToString();
  57.             }
  58.  
  59.         }
  60.  
  61.         #region Web Form Designer generated code
  62.         override protected void OnInit(EventArgs e)
  63.         {
  64.             //
  65.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  66.             //
  67.             InitializeComponent();
  68.             base.OnInit(e);
  69.         }
  70.  
  71.         /// <summary>
  72.         /// Required method for Designer support - do not modify
  73.         /// the contents of this method with the code editor.
  74.         /// </summary>
  75.         private void InitializeComponent()
  76.         {    
  77.             this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
  78.             this.Load += new System.EventHandler(this.Page_Load);
  79.  
  80.         }
  81.         #endregion
  82.  
  83.  
  84.  
  85.         private void cmdSubmit_Click(object sender, System.EventArgs e)
  86.         {
  87.             SqlConnection oConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
  88.             SqlDataAdapter da=new SqlDataAdapter("dbo.writeAccomplishment", oConn);
  89.             da.SelectCommand.CommandType=CommandType.StoredProcedure;
  90.  
  91.             da.SelectCommand.Parameters.Add(new SqlParameter("@FirstName",txtFirstName.Text));
  92.             da.SelectCommand.Parameters.Add(new SqlParameter("@LastName",txtLastName.Text));
  93.             da.SelectCommand.Parameters.Add(new SqlParameter("@AccompDesc",txtdescription.Text));
  94.             da.SelectCommand.Parameters.Add(new SqlParameter("@datecreated",txtdatecreated.Text));
  95.             da.SelectCommand.Parameters.Add(new SqlParameter("@deptname",txtdept.Text));
  96.             da.SelectCommand.Parameters.Add(new SqlParameter("@ProjectId",drpProject.SelectedItem.Value));
  97.  
  98. //                        SqlParameter ReturnID = new SqlParameter("@EmployeeID", SqlDbType.Int); 
  99. //                        ReturnID.Direction = ParameterDirection.Output; 
  100. //                        da.SelectCommand.Parameters.Add(ReturnID);
  101.             oConn.Open();
  102.             da.SelectCommand.ExecuteNonQuery();
  103.             oConn.Close();
  104.  
  105.  
  106.         }
  107.     }
  108.  
  109.  
  110. }
  111.  
  112.  
  113.  
  114.  
and here is the store procedure
Expand|Select|Wrap|Line Numbers
  1. CREATE procedure dbo.writeAccomplishment
  2.  
  3.  
  4. (
  5.  @firstname varchar(50),
  6.  @lastname varchar(50),
  7.  @AccompDesc varchar(2000),
  8.  @DeptName varchar(50),
  9.  @Projectid int,
  10.  @datecreated datetime,
  11. @Employeeid int 
  12.  
  13. )
  14. as
  15.  
  16. --declare @employeeid int
  17. select EmployeeID from Employee
  18. where employeeid=@Employeeid
  19.  
  20. IF  EXISTS(SELECT employeeid FROM Employee WHERE  Firstname = @FirstName and LastName=@LastName)
  21.  
  22. BEGIN
  23. SELECT 'This record already exists!'
  24.  
  25. --insert into Employee
  26.  
  27. --(EmployeeId)--,FirstName, LastName,DeptName)
  28.  
  29.  
  30. --Values (@@Identity)--,@FirstName,@LastName,@DeptName)
  31.  
  32.  
  33. Insert into Accomplishment (Employeeid,AccompDesc,ProjectId,Datecreated)
  34.  
  35. values (@employeeid,@AccompDesc,@ProjectId,@datecreated)
  36.  
  37. END
  38. else
  39. BEGIN
  40. --SELECT 'Add this EmployeeID'
  41.  
  42. insert into Employee
  43.  
  44. (DeptName,FirstName,LastName)
  45.  
  46. Values (@DeptName,@FirstName,@LastName)
  47.  
  48.  
  49. Insert into Accomplishment (Employeeid,AccompDesc,Projectid,datecreated)
  50.  
  51. values (@employeeid,@AccompDesc,@projectid,@datecreated)
  52.  
  53. --set @employeeID =  @employeeid
  54.  
  55. --return @employeeID
  56. END
  57. GO
  58.  
  59.  
  60.  
Oct 11 '07 #1
4 2072
nateraaaa
663 Expert 512MB
The parameters that you pass must match the parameter names in your stored procedure

da.SelectCommand.Parameters.Add(new SqlParameter("@FirstName",txtFirstName.Text));
da.SelectCommand.Parameters.Add(new SqlParameter("@LastName",txtLastName.Text));
da.SelectCommand.Parameters.Add(new SqlParameter("@AccompDesc",txtdescription.Text));
da.SelectCommand.Parameters.Add(new SqlParameter("@datecreated",txtdatecreated.Text));
da.SelectCommand.Parameters.Add(new SqlParameter("@deptname",txtdept.Text));
da.SelectCommand.Parameters.Add(new SqlParameter("@ProjectId",drpProject.SelectedItem.Value));

Change the parameters you are passing to match identically to the parameters defined in the stored procedure.

Nathan
Oct 11 '07 #2
hey i have a employeeid too but i don't have a text box for that employeeid i need to pass the value to employeeid not know how i can do that please help me
Oct 11 '07 #3
nateraaaa
663 Expert 512MB
hey i have a employeeid too but i don't have a text box for that employeeid i need to pass the value to employeeid not know how i can do that please help me
Based on your proc it looked like you were trying to make the employeeid an @@Identity column. If this is the case employeeid would autoincrement each time a new employee was inserted into your table. There is no need to pass a parameter to do this. Your stored proc will do it for you. If you are unsure about what your stored proc is doing post your proc in the SQL forum and they can help you get the stored proc written correctly.

Nathan
Oct 11 '07 #4
i am getting this error don't what to do

Cannot insert the value NULL into column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated.
Oct 11 '07 #5

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

Similar topics

15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
1
by: knowthediff | last post by:
Hello, I have a VS2003 app that I moved to VS 2005. I am trying to correct the error that I now receive when the app runs. In several places I am getting a InvalidOperationException...
1
by: bagya | last post by:
please help me out the following is the small code i have <html> <head> <script type="text/javascript"> function validate() { if (document.abc.region.value==0)
2
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.