Can i give auto increment to stateID and productID or should i allow nulls???http://forums.asp.net/t/1763279.aspx/1?Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Thu, 02 Feb 2012 04:13:29 -050017632794803899http://forums.asp.net/p/1763279/4803899.aspx/1?Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Can i give auto increment to stateID and productID or should i allow nulls??? I have three tables Table(1):with CustomerID(PrimaryKEy), StateID(Foreign Key), ProductID(FK)., customername, state, city, zipcode. Table (2): StateID(primary Key), states Table(3): ProductID(Primary Key), products Now, i want to insert values into Table(1). I'm getting an error coz i have'nt allowed nulls for stateID and productID. Can i give auto increment to stateID and productID or should i allow nulls??? By the way Table(2) states field is only for four items to be populated in Dropdownlist. similarly Table(3) Products. Plz suggest me.... 2012-01-27T17:04:52-05:004804169http://forums.asp.net/p/1763279/4804169.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>Ideally, you would want to know the StateID and ProductID at the time of your insert into the Customer table.&nbsp; If you can't do this for some reason, you can leave them null.&nbsp; I would not recommend auto-increment because then the foreign keys would not tie up correctly to the State or Product tables.&nbsp; </p> <p>If you do allow null, and you want to write a query that joins all three tables, be sure to use a LEFT OUTER JOIN to make sure all of your Customer data is returned with null values for the State and Product data.</p> <p>&nbsp;</p> <p>Matt</p> 2012-01-27T20:06:03-05:004805599http://forums.asp.net/p/1763279/4805599.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>Problem with row_updating Event!!!!!!!!!!!!!!!!! </p> <p>protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial </p> <p>&nbsp;</p> <pre class="prettyprint">Problem with row_updating Event protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=True&quot;); SqlCommand cmd = new SqlCommand(&quot;usp_state&quot;, con); con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); cmd.ExecuteScalar(); ddlstate.DataTextField = &quot;StateNames&quot;; ddlstate.DataValueField = &quot;StateID&quot;; ddlstate.DataSource = ds; ddlstate.DataBind(); ddlstate.Items.Insert(0, new ListItem(&quot;Select&quot;)); con.Close(); SqlConnection con1 = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=True&quot;); SqlCommand cmd1 = new SqlCommand(&quot;usp_products&quot;, con1); con1.Open(); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataSet ds1 = new DataSet(); da1.Fill(ds1); cmd1.ExecuteScalar(); ddlproducts.DataTextField = &quot;Products&quot;; ddlproducts.DataValueField = &quot;ProductID&quot;; ddlproducts.DataSource = ds1; ddlproducts.DataBind(); ddlproducts.Items.Insert(0, new ListItem(&quot;Select&quot;)); con1.Close(); } bindgrid(); } protected void btnsubmit_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=True&quot;); SqlCommand cmd = new SqlCommand(&quot;usp_insert&quot;, con); con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&quot;@CustomerName&quot;, txtcustname.Text); cmd.Parameters.AddWithValue(&quot;@Address&quot;, txtadd.Text); cmd.Parameters.AddWithValue(&quot;@City&quot;, txtcity.Text); cmd.Parameters.AddWithValue(&quot;@Zipcode&quot;, txtzip.Text); cmd.Parameters.AddWithValue(&quot;@RegistrationDate&quot;, txtregdate.Text); cmd.Parameters.AddWithValue(&quot;@Email&quot;, txtemail.Text); cmd.Parameters.Add(&quot;@StateID&quot;,SqlDbType.Int).Value = ddlstate.SelectedItem.Value; cmd.Parameters.Add(&quot;@ProductID&quot;,SqlDbType.Int).Value = ddlproducts.SelectedItem.Value; DataSet ds = new DataSet(); da.Fill(ds); cmd.ExecuteNonQuery(); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; bindgrid(); } public void bindgrid() { SqlConnection con = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=True&quot;); SqlCommand cmd = new SqlCommand(&quot;usp_join&quot;, con); con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); cmd.ExecuteScalar(); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; bindgrid(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { SqlConnection con = new SqlConnection(&quot;Data Source=STD-258E51EA446\\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=True&quot;); SqlCommand cmd = new SqlCommand(&quot;usp_update&quot;, con); con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&quot;@CustomerID&quot;, SqlDbType.Int); cmd.Parameters.AddWithValue(&quot;@CustomerName&quot;, SqlDbType.VarChar); cmd.Parameters.AddWithValue(&quot;@Address&quot;, SqlDbType.VarChar); cmd.Parameters.AddWithValue(&quot;@City&quot;, SqlDbType.VarChar); cmd.Parameters.AddWithValue(&quot;@Zipcode&quot;, SqlDbType.VarChar); cmd.Parameters.AddWithValue(&quot;@RegistrationDate&quot;, SqlDbType.DateTime); cmd.Parameters.AddWithValue(&quot;@Email&quot;, SqlDbType.VarChar); DataSet ds = new DataSet(); da.Fill(ds); cmd.ExecuteNonQuery(); //GridView1.DataSource = ds; //GridView1.DataBind(); GridView1.EditIndex = -1; bindgrid(); con.Close(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; bindgrid(); } } &quot;S.P&quot; [usp_join] SELECT Customer.CustomerName,Customer.Address, State.StateNames,Customer.City,Customer.Zipcode,Customer.Email,Customer.RegistrationDate,Product.Products From Customer Left outer join State on Customer.StateID = State.StateID Left outer join Product on Customer.ProductID = Product.ProductID &quot;S.P&quot; [usp_insert] (@CustomerName varchar(50),@Address varchar(50), @City varchar(50), @Zipcode varchar(6),@RegistrationDate Datetime, @Email varchar(50),@StateID int,@ProductID int) AS insert into Customer (CustomerName ,Address , City , Zipcode ,RegistrationDate , Email ,StateID ,ProductID) values (@CustomerName ,@Address , @City , @Zipcode ,@RegistrationDate , @Email ,@StateID ,@ProductID) &quot;S.P&quot; [usp_update] (@CustomerID int,@CustomerName varchar(50),@Address Varchar(50),@City varchar(50),@Zipcode varchar(50),@Email Varchar(50),@RegistrationDate Datetime) AS update Customer set CustomerName=@CustomerName, Address=@Address, City=@city, Zipcode=@Zipcode, Email=@Email, RegistrationDate=@RegistrationDate where CustomerID=@CustomerID</pre> <p>&nbsp;</p> <p>&nbsp;</p> 2012-01-29T18:35:27-05:004811640http://forums.asp.net/p/1763279/4811640.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>Hello rookie tiro</p> <p>So you've found the issue and your problem gets solved</p> 2012-02-02T01:18:36-05:004811721http://forums.asp.net/p/1763279/4811721.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>No that didnt solve me. I had done it my own way. I havent done them giving nulls.</p> 2012-02-02T03:23:54-05:004811767http://forums.asp.net/p/1763279/4811767.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>Hello again</p> <p>It seems that your problem appears thereand I'll reply there</p> <p><a href="http://forums.asp.net/p/1763680/4811730.aspx/1?Re&#43;Problem&#43;with&#43;updating&#43;">http://forums.asp.net/p/1763680/4811730.aspx/1?Re&#43;Problem&#43;with&#43;updating&#43;</a></p> 2012-02-02T04:13:29-05:004811768http://forums.asp.net/p/1763279/4811768.aspx/1?Re+Can+i+give+auto+increment+to+stateID+and+productID+or+should+i+allow+nulls+Re: Can i give auto increment to stateID and productID or should i allow nulls??? <p>Hello again</p> <p>It seems that your problem appears thereand I'll reply there</p> <p><a href="http://forums.asp.net/p/1763680/4811730.aspx/1?Re&#43;Problem&#43;with&#43;updating&#43;">http://forums.asp.net/p/1763680/4811730.aspx/1?Re&#43;Problem&#43;with&#43;updating&#43;</a></p> 2012-02-02T04:13:29-05:00