I am creating a page which adds a product to my SQL table. I have seen and modified a snippet of code for my need.
string contentType = ImageUpld.PostedFile.ContentType;
using (Stream fs = ImageUpld.PostedFile.InputStream)
{
using (BinaryReader br = new BinaryReader(fs))
{
byte[] bytes = br.ReadBytes((Int32)fs.Length);
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO Products (Name, Image, Price, Desc, Author, Preview, ContentType ) VALUES ('" + Nametxt.Text + "', '" + bytes + "', '" + Pricetxt.Text + "', '" + Desctxt.Text + "', '" + Session["UserName"] + "', '" + Previewtxt.Text + "')", conn);
cmd.CommandType = CommandType.Text;
using (conn)
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
conn.Close();
}
}
}
Visual Studio highlights the cmd.ExecuteReader();
then says:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Incorrect syntax near the keyword 'Desc'.