1
Answer

Incorrect Syntax near publishedAt

Ramco Ramco

Ramco Ramco

1w
63
1

HI

  I am getting error - Incorrect Syntax near publishedAt at cmd.ExecuteNonQuery();

private void InsertVideoDetails(string VideoId,  string VideoTitle, string Description, int ViewCount, string LikeCount,  string CommentCount, DateTime PublishedAt)
        {
            string sql = "INSERT INTO Videos (VideoId, VideoTitle, Description,LikeCount, ViewCount,CommentCount,Published_At) VALUES (@VideoId, @VideoTitle, @Description,@LikeCount, @ViewCount,@CommentCount,@PublishedAt";
            string constring = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constring))
            {
                using (SqlCommand cmd = new SqlCommand(sql))
                {
                    cmd.Parameters.AddWithValue("@VideoId", VideoId);
                    cmd.Parameters.AddWithValue("@VideoTitle", VideoTitle);
                    cmd.Parameters.AddWithValue("@Description", Description);
                    cmd.Parameters.AddWithValue("@LikeCount", LikeCount);
                    cmd.Parameters.AddWithValue("@ViewCount", ViewCount);
                    cmd.Parameters.AddWithValue("@CommentCount", CommentCount);
                    cmd.Parameters.AddWithValue("@PublishedAt", PublishedAt);
                    cmd.Connection = con;
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }

Thanks

Answers (1)