18
Answers

error Cannot insert the value NULL into column 'id', table

aditya immadi

aditya immadi

11y
3.8k
1
Cannot insert the value NULL into column 'id', table

i got the Above error after i alter the table with id column...i m little bit confused can any one rectifie this..

my .cs code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;


namespace ApComapaign
{
    public partial class admim_newuser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btninsert_Click(object sender, EventArgs e)
        {


            string filename = Path.GetFileName(FileUploadC.PostedFile.FileName);
            filename = txtnameC.Text + "_" + filename;
            FileUploadC.SaveAs(Server.MapPath("~/Images-candidates/" + filename));
           
            string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            SqlConnection conn = new SqlConnection(constring);
            cmd.Connection = conn;
            conn.Open();

            cmd.CommandText = "[SP_Candidate]";
            cmd.CommandType = CommandType.StoredProcedure;
           
            cmd.Parameters.AddWithValue("name", txtnameC.Text);
            cmd.Parameters.AddWithValue("image", filename);
            cmd.Parameters.AddWithValue("role", ddlCRole.Text);
            cmd.Parameters.AddWithValue("party", ddlCparty.Text);
            cmd.Parameters.AddWithValue("area", txtarea.Text);
            cmd.Parameters.AddWithValue("district", txtdis.Text);
            cmd.Parameters.AddWithValue("fb", txtfb.Text);
            cmd.Parameters.AddWithValue("blog", txtblog.Text);
            cmd.Parameters.AddWithValue("twitter", txttwitt.Text);
            cmd.Parameters.AddWithValue("wiki", txtwiki.Text);
            cmd.Parameters.AddWithValue("web", txtweb.Text);

            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = cmd;
            da.Fill(ds);
            cmd.ExecuteNonQuery();
            conn.Close();

        }
    }
}


thanks and regards
Answers (18)