473,387 Members | 1,863 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,387 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 2077
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.