Matthijs
Matthijs

Reputation: 3170

Insert date into database winforms

I am trying to insert a row in my table with a bunch of data, including a date (using the Date type field)

The input is received from a usercontrol and then put into parameters:

        cmd.Parameters.AddWithValue("titel", titel);
        cmd.Parameters.AddWithValue("dvu" , dvu );
        cmd.Parameters.AddWithValue("genre", genreID);
        cmd.Parameters.AddWithValue("paginas", paginas);
        cmd.Parameters.AddWithValue("taal", taalID);
        cmd.Parameters.AddWithValue("isbn13", isbn13);
        cmd.Parameters.AddWithValue("isbn10", isbn10);
        cmd.Parameters.AddWithValue("uitgever", uitgever);
        cmd.Parameters.AddWithValue("auteur", auteurID);
        cmd.Parameters.AddWithValue("bindwijze", bindwijzeID);

As shown above, the 'dvu' is the date to be added. It's format entered is DD-MM-YYYY. However, when I execute the query as follows:

        conn.Open();
        cmd.CommandText = "INSERT INTO Boek (ItemID, AuteurID, BoekGenreID,
        BindwijzeID, TaalID, ISBN10, ISBN13, AantalPagina) 
        VALUES (@itemID, @auteur, @genre, @bindwijze, 
        @taal, @isbn10, @isbn13, @paginas);";
        cmd.ExecuteNonQuery();
        conn.Close();

The date does not get inserted into the database, where as the other data does get inserted.

How can I fix this?

Edit: Fixed. I totally forgot to include them in my query! :/ Sorry!

Upvotes: 0

Views: 670

Answers (1)

Steve
Steve

Reputation: 216243

Your query doesn't contain the field name and the parameter. Of course nothing is inserted in the table for the field (suppose it is called DVU)

    conn.Open();
    cmd.CommandText = "INSERT INTO Boek (ItemID, DVU, AuteurID, BoekGenreID,
    BindwijzeID, TaalID, ISBN10, ISBN13, AantalPagina) 
    VALUES (@itemID, @dvu, @auteur, @genre, @bindwijze, 
    @taal, @isbn10, @isbn13, @paginas);";
    cmd.ExecuteNonQuery();
    conn.Close();

Upvotes: 2

Related Questions