Note that there are some explanatory texts on larger screens.

plurals
  1. POMaskedTextBox If empty insert NULL into SQL
    primarykey
    data
    text
    <p>I have got this code below which care whether <code>maskedtextbox is empty</code>. If it is empty it <code>INSERT INTO</code> SQL table <code>__.__.____</code> - only the mask so I believe it <code>INSERTS NULL</code> But something got wrong when I fill the <code>maskedtextbox</code>. It still <code>INSERT</code> <code>__.__.____</code> - NULL I don't know where I make mistake because it should normally insert the <code>date</code> which is in the maskedtextbox.</p> <p>The mask for this textbox is <code>__.__.____</code> like <code>00/00/0000</code></p> <p>Data type in which I insert this data is - date. </p> <p>Here is the code:</p> <pre><code>var value2 = (object)DBNull.Value; DateTime parsedDate2; if (DateTime.TryParseExact(maskedTextBox2.Text, "__.__.____", null, DateTimeStyles.None, out parsedDate2)) { value2 = parsedDate2; } prikaz.Parameters.AddWithValue("@odjdate", value2); </code></pre> <p>Edit : This code below says: the name 'value2' does not exist in the current context'</p> <pre><code>var value2 = (object)DBNull.Value; DateTime parsedDate2; if (DateTime.TryParseExact(maskedTextBox2.Text, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate2)) { value2 = parsedDate2; } prikaz.Parameters.AddWithValue("@odjdate", value2); </code></pre> <p>This code below does this Ex:</p> <pre><code>Converting into data type date wasn't succesfull. </code></pre> <p>This is the code</p> <pre><code>if (maskedTextBox2.Text == "__.__.____") { prikaz.Parameters.AddWithValue("@odjdate", null); } else { prikaz.Parameters.AddWithValue("@odjdate",maskedTextBox2.Text); } </code></pre>
    singulars
    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