472,993 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

Getting the Null value error

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
Expand|Select|Wrap|Line Numbers
  1. Cannot insert the value NULL into column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated. 
  2.  
  3.  
and my code is this
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.TextBox txtemployee;
  34.         protected System.Web.UI.WebControls.Button cmdSubmit;
  35.  
  36.         private void Page_Load(object sender, System.EventArgs e)
  37.         {
  38.             txtdatecreated.Text = DateTime.Now.ToShortDateString();
  39.             // Put user code to initialize the page here
  40.             if(Session["Login"].ToString() != null)
  41.             {
  42.                 this.txtLogin.Text=Session["Login"].ToString();
  43.             }
  44.  
  45.             if(Session["fn"].ToString() != null)
  46.             {
  47.                 this.txtFirstName.Text=Session["fn"].ToString();
  48.             }
  49.  
  50.             if(Session["sn"].ToString() != null)
  51.             {
  52.                 this.txtLastName.Text=Session["sn"].ToString();
  53.             }
  54.  
  55.             if(Session["department"].ToString() != null)
  56.             {
  57.                 this.txtdept.Text=Session["department"].ToString();
  58.             }
  59.  
  60.         }
  61.  
  62.         #region Web Form Designer generated code
  63.         override protected void OnInit(EventArgs e)
  64.         {
  65.             //
  66.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  67.             //
  68.             InitializeComponent();
  69.             base.OnInit(e);
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Required method for Designer support - do not modify
  74.         /// the contents of this method with the code editor.
  75.         /// </summary>
  76.         private void InitializeComponent()
  77.         {    
  78.             this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
  79.             this.Load += new System.EventHandler(this.Page_Load);
  80.  
  81.         }
  82.         #endregion
  83.  
  84.  
  85.  
  86.         private void cmdSubmit_Click(object sender, System.EventArgs e)
  87.         {
  88.  
  89.  
  90.             SqlConnection oConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]);
  91.             SqlDataAdapter da=new SqlDataAdapter("dbo.win_insertName_test", oConn);
  92.             da.SelectCommand.CommandType=CommandType.StoredProcedure; 
  93.  
  94.             da.SelectCommand.Parameters.Add(new SqlParameter("@FirstName",txtFirstName.Text));
  95.             da.SelectCommand.Parameters.Add(new SqlParameter("@LastName",txtLastName.Text));
  96.             da.SelectCommand.Parameters.Add(new SqlParameter("@AccompDesc",txtdescription.Text));
  97.             da.SelectCommand.Parameters.Add(new SqlParameter("@datecreated",txtdatecreated.Text));
  98.             da.SelectCommand.Parameters.Add(new SqlParameter("@deptname",txtdept.Text));
  99.             da.SelectCommand.Parameters.Add(new SqlParameter("@ProjectId",drpProject.SelectedItem.Value));
  100.  
  101.             SqlParameter employeeid = new SqlParameter("@employeeID", SqlDbType.Int); 
  102.             employeeid.Direction = ParameterDirection.Output; 
  103.             da.SelectCommand.Parameters.Add(employeeid);
  104.  
  105.  
  106.             SqlParameter newid = new SqlParameter("@newID", SqlDbType.Int); 
  107.             newid.Direction = ParameterDirection.Output; 
  108.             da.SelectCommand.Parameters.Add(newid);
  109.  
  110.  
  111.             oConn.Open();
  112.             da.SelectCommand.ExecuteNonQuery();
  113.             oConn.Close();
  114.  
  115.  
  116.         }
  117.     }
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
and the store procedure is this
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.win_insertName_test
  2.  
  3. (
  4.  
  5.  @FirstName varchar(25),
  6.  
  7.  @LastName varchar(25), 
  8.  
  9.  @DeptName Varchar(25),
  10.  
  11.  @Accompdesc Varchar(3000),
  12.  
  13.  @datecreated datetime,
  14.  
  15.  @projectID int, 
  16. @NewID int output ,
  17.   @employeeID int output
  18.  
  19.  
  20. )
  21.  
  22.  
  23. AS
  24.  
  25. IF EXISTS(SELECT EmployeeID FROM Employee WHERE FirstName = @firstName and LastName=@LastName)
  26.  
  27. BEGIN
  28.  
  29. --This means it exists, return it to your application
  30. set @employeeid=@newid
  31. SELECT 'This record already exists!'
  32.  
  33. Insert Into Accomplishment(EmployeeID,AccompDesc,ProjectID,DateCreated)
  34.  
  35. values(@employeeid,@AccompDesc,@ProjectID,@DateCreated)
  36.  
  37. END
  38.  
  39. ELSE
  40.  
  41. BEGIN
  42.  
  43. --This means the record isn't in there already, add it
  44.  
  45. SELECT 'Add this Record'
  46.  
  47. INSERT into Employee(FirstName, LastName, DeptName) VALUES(@FirstName, @LastName,@DeptName)
  48.  
  49. Set @NewID=Scope_Identity();
  50.  
  51. END
  52.  
  53.  
  54. GO
  55.  
  56.  
  57.  
Oct 18 '07 #1
2 2370
Plater
7,872 Expert 4TB
Please do not double post (http://www.thescripts.com/forum/thread721761.html )
You already had some good answers given there.

@EmployedID is marked as output, but never appears to get a value?
You do a SELECT statement with it before it gets a value (so it's still null)
You also try and use @NewID before it gets a value too (also marked as output)
Oct 18 '07 #2
i am really sorry i should check first before post the question once again i am sorry
Oct 18 '07 #3

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

Similar topics

4
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
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) :...
10
by: Rahul Babbar | last post by:
Hi, I am getting the following error, while executing the simple insert script on a few tables. INSERT INTO <table_name>(<col1>) VALUES (1); DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884,...
4
by: preeti13 | last post by:
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 using System;...
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...
0
by: =?Utf-8?B?RmFicml6aW8gQ2lwcmlhbmk=?= | last post by:
I need to access classic ASP intrinsic objects and their properties from a ..net assembly wrapped to COM. The COM .net assembly is then instanciated from a classic ASP page with...
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.