I'm trying to create an admin dashboard, and within that same dashboard make an option to add articles. For some reason I'm getting this error:

System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'file'.

This is a part of the code i used for the "news portal" I'm trying to build. This is the server-side code behind the dashboard aspx page.

protected void Publish_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

    con.Open();
    string command = "INSERT INTO Articles(title,author,content,file,tags) VALUES(@title,@author,@content,@file,@tags)";
    SqlCommand cmd = new SqlCommand(command, con);

    cmd.Parameters.AddWithValue("@title", Title1.Text);
    cmd.Parameters.AddWithValue("@author", Author.Text);
    cmd.Parameters.AddWithValue("@content", Content.Text);
    string strImg = System.IO.Path.GetFileName(File1.PostedFile.FileName);
    cmd.Parameters.AddWithValue("@file", strImg);
    cmd.Parameters.AddWithValue("@tags", Tag.Text);
    cmd.ExecuteNonQuery();
    con.Close();
    File1.PostedFile.SaveAs(Server.MapPath("Images\\") + strImg);
}

I'm getting this error every single time I press the "publish" button.

Related posts

Recent Viewed