"Invalid column name" when trying to insert data into database using SQL
<p>I'm trying to insert new values into my database using visual studio and here is my code: </p>

<pre><code>SqlCommand cmd = new SqlCommand();

SqlConnection conn = new SqlConnection();
conn.ConnectionString = dbconnectionstring;
conn.Open();

cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Data_ConfigInfo (TypeID, Name, ValidFromDate, ValidToDate, ValidFromSOP, ValidToSOP, Description)" +
                  "VALUES(@TypeID, @Name, @ValidFromDateTime, @ValidToDateTime, @ValidFromSOP, @ValidToSOP, @Description)";

cmd.Parameters.AddWithValue("TypeID", Logg.TypeID);
cmd.Parameters.AddWithValue("Name", Logg.Name);

if(Logg.ValidFrom.Equals(null)) {
     cmd.Parameters.AddWithValue("@ValidFromDateTime", DBNull.Value);
}
else
{
    cmd.Parameters.AddWithValue("@ValidFromDateTime", Logg.ValidFrom);
}

if (Logg.ValidTo.Equals(null))
{
    cmd.Parameters.AddWithValue("@ValidToDateTime", DBNull.Value);
}
else
{
    cmd.Parameters.AddWithValue("@ValidToDateTime", Logg.ValidFrom);
}

cmd.Parameters.AddWithValue("@ValidFromSOP", Logg.ValidFromSOP);
cmd.Parameters.AddWithValue("@ValidToSOP", Logg.ValidToSOP);
cmd.Parameters.AddWithValue("@Description", Logg.Description);

cmd.ExecuteNonQuery();
conn.close();
conn.dispose();
</code></pre>

<p>But at the line </p>

<pre><code>cmd.ExecuteNonQuery(); 
</code></pre>

<p>I get the error </p>

<blockquote>
  <p>invalid column name for ValidToDateTime and ValidFromDateTime. </p>
</blockquote>

<p>Both are datetime variables. I can't seem to find the error. Any ideas? </p>

<p>This is how my datatable looks</p>

<p><a href="https://i.stack.imgur.com/HaobX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaobX.png" alt="Datatable structure"></a></p>