Note that there are some explanatory texts on larger screens.

plurals
  1. POC# check insert value is empty or null in cause of overwrite with empty string
    primarykey
    data
    text
    <p>I have a class with different attributes, lets say.</p> <pre><code>Object.attributeA Object.attributeB Object.attributeC Object.attributeD </code></pre> <p>However, they are not always filled. For example:</p> <pre><code>Object.attributeA = "string"; Object.attributeB = "string"; Object.attributeC = null; Object.attributeD = "string"; </code></pre> <p>My insert statement looks like this:</p> <pre><code>string sql = @"INSERT INTO TABLE ( attributeA, attributeB, attributeC, attributeAD ) values ( @attributeA, @attributeB, @attributeC, @attributeAD );"; SqlParameter[] parameters = { new SqlParameter("@attributeA", SqlDbType.NVarChar) {Value = attributeA}, new SqlParameter("@attributeB", SqlDbType.NVarChar) {Value = attributeB}, new SqlParameter("@attributeC", SqlDbType.NVarChar) {Value = attributeC}, new SqlParameter("@attributeD", SqlDbType.NVarChar) {Value = attributeD} }; ExecuteNoNQuery(sql, parameters); </code></pre> <p>How do I insert a null?</p> <p>(To confirm: when I update a row I want to keep the old value if the new value is null, with "" I just OVERWRITE the old value right?)</p> <p>Old row "abc" "abc" "abc" "abc"</p> <p>Update row: "string" "string" "abc" "string" </p> <p>AND NOT: "string" "string" "" "string"</p> <p>EDIT: I have two tables. I use the insert for the first table, add the attributes (sort of a temp save) AND THEN I take this table row for row update the 'real' table. The attributes in table 1 are always more then the real table. That's why after the insert of a "" I just overwrite the attribute in the real table.</p> <p>My update function looks something like this:</p> <pre><code>public void UpdateBatchToRealTable(Class, int id) { // Current Batch DataTable dt = DAL.Batch(id); // table 1 (temp table) -&gt; table 2 (real table) DataRow row = dt.Rows[0]; Object.attributeA = row["attributeA"].ToString(); Object.attributeB = row["attributeB"].ToString(); Object.attributeC = row["attributeC"].ToString(); Object.attributeD = row["attributeD"].ToString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload