By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

Cannot insert the value NULL into column 'employeeid', table 'training.dbo.employee';

P: 1
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Configuration;
  10.  
  11.  
  12.  
  13. public partial class add : System.Web.UI.Page
  14. {
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.  
  18.     }
  19.     protected void btnadd_Click(object sender, EventArgs e)
  20.     {
  21.         int result = 0;
  22.         SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
  23.         SqlCommand cmd = new SqlCommand("insertemployee", con);
  24.         cmd.CommandType = CommandType.StoredProcedure;
  25.         cmd.Parameters.Add("@employeename", SqlDbType.NVarChar, 50).Value = ename.Text.Trim();
  26.         cmd.Parameters.Add("@employeecourse", SqlDbType.NVarChar, 50).Value = ecourse.Text.Trim();
  27.         con.Open();
  28.         result = cmd.ExecuteNonQuery();
  29.             con.Close();
  30.             if (result > 0)
  31.                 Response.Write("employees are added");
  32.             else
  33.                 Response.Write("insertion in problems");
  34.  
  35.  
  36.     }
  37. }
  38.  
  39.  
  40. MY STOREPROCEDURES IS THIS
  41. USE [training]
  42. GO
  43. /****** Object:  StoredProcedure [dbo].[insertemployee]    Script Date: 11/28/2012 16:40:07 ******/
  44. SET ANSI_NULLS ON
  45. GO
  46. SET QUOTED_IDENTIFIER ON
  47. GO
  48.  
  49. ALTER PROCEDURE [dbo].[insertemployee](@employeename nvarchar(50),@employeecourse nvarchar(50))
  50. AS
  51. BEGIN
  52. INSERT INTO [employee]([employeename],[employeecourse])
  53.  
  54. VALUES
  55. (@employeename,@employeecourse)
  56.  
  57.  
  58. END
Nov 28 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,359
That is a very straight forward error. The employeeid field in the table training.dbo.employee can not be null.
Nov 28 '12 #2

Post your reply

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