cannot insert null value into the table Orders <p>i am having a problem regarding inserting records to my database, the error says: "Cannot insert the value NULL into column 'OrderNo', table 'Receipt.dbo.Orders'; column does not allow nulls. Insert Fails. then the statement has been terminated", but when i checked my codes, i cannot seem to find any error. Can somebody help me? Thank you in advance:</p> <p>Here is my set of codes:</p> <p>-for save sales order-</p> <pre><code>private void SaveSalesOrder(string status) { int nOrder = 0; CloseConnection(); OpenConnection(); trnOrder = cn.BeginTransaction(); SqlCommand cmdInsert = new SqlCommand(); try { cmdInsert.Connection = cn; cmdInsert.Transaction = trnOrder; cmdInsert.CommandType = CommandType.Text; cmdInsert.CommandText = "INSERT INTO Orders " + "(OrderDate, CustomerNo, CustomerName, CustomerAddress, PurchaseOrderNo, AgentName, Status) " + "VALUES ('" + dtpOrderDate.Value.Date.ToString() + "', '" + txtCustomerNo.Text + "', '" + txtCustomerName.Text + "', '" + txtCustomerAddress.Text + "', '" + txtPONo.Text + "', '" + cboAgentName.Text + "', '" + status + "'); " + "SELECT TOP 1 OrderNo FROM Orders " + "ORDER BY OrderNo DESC;"; nOrder = Convert.ToInt16(cmdInsert.ExecuteScalar().ToString()); for (int nRow = 0; nRow &lt;= dsDetail.Tables["OrderDetails"].Rows.Count - 1; nRow++) { double dQuantity = Convert.ToDouble(dsDetail.Tables["OrderDetails"]. Rows[nRow]["Quantity"].ToString()); string strUnit = dsDetail.Tables["OrderDetails"]. Rows[nRow]["Unit"].ToString(); int nProductNo = Convert.ToInt16(dsDetail.Tables["OrderDetails"]. Rows[nRow]["ProductNo"].ToString()); string strProductName = dsDetail.Tables["OrderDetails"]. Rows[nRow]["ProductName"].ToString(); string strProductSize = dsDetail.Tables["OrderDetails"]. Rows[nRow]["ProductSize"].ToString(); string strPackagingInside = dsDetail.Tables["OrderDetails"]. Rows[nRow]["PackagingInside"].ToString(); double dSellingDiscount = Convert.ToDouble(dsDetail.Tables["OrderDetails"]. Rows[nRow]["SellingDiscount"].ToString()); double dSellingPrice = Convert.ToDouble(dsDetail.Tables["OrderDetails"]. Rows[nRow]["SellingPrice"].ToString()); double nAmount = Convert.ToDouble(dsDetail.Tables["OrderDetails"]. Rows[nRow]["Amount"].ToString()); SqlCommand cmdInsertDetail = new SqlCommand(); cmdInsertDetail.Connection = cn; cmdInsertDetail.Transaction = trnOrder; cmdInsertDetail.CommandType = CommandType.Text; cmdInsertDetail.CommandText = "INSERT INTO OrderDetails " + "(OrderNo, PackagingOutside, Quantity, Unit, ProductNo, ProductName, " + "ProductSize, PackagingInside, SellingDiscount, SellingPrice, Amount) " + "VALUES ('" + nOrder + "', '" + dPackagingOutside + "', '" + dQuantity + "', '" + strUnit + "', '" + nProductNo + "', '" + strProductName + "', '" + strProductSize + "', '" + strPackagingInside + "', '" + dSellingDiscount + "', '" + dSellingPrice + "', '" + nAmount + "')"; cmdInsertDetail.ExecuteNonQuery(); } trnOrder.Commit(); if (status == "OK") { MessageBox.Show("Transaction has been saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Transaction has been voided!", "Void Transaction", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (SqlException ex) { trnOrder.Rollback(); MessageBox.Show(ex.Message); } finally { cn.Close(); } } private void btnSave_Click(object sender, EventArgs e) { if (txtCustomerNo.Text == "") { MessageBox.Show("Please select a customer first.", "Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); btnSearchCustomer.Focus(); return; } if (grdDetails.Rows.Count &lt; 1) { MessageBox.Show("Please select a product first.", "Empty", MessageBoxButtons.OK, MessageBoxIcon.Error); btnProductSearch.Focus(); return; } SaveSalesOrder("OK"); groupCustomer(false); groupProduct(false); CSalesInv.EnableDisable(this, false); CloseConnection(); InitializeOrder(); lblTotal.Text = ""; } </code></pre>