1
Answer

Uploading Image File to a DataBase

Carlos Sanchez

Carlos Sanchez

20y
1.3k
1
Somebody know how to upload a Image File to a DataBase. The file is selceted by the user by a OpenFileDialog. if (OpenFileDialog1.Show()==DialogResult.Ok) { Image img = Image.FromFile(OpenFileDialog1.FileName) //Uploading img to the DataBase } I have the next wrong code to Upload img to the DataBase: SqlCommand InsertCommand = new SqlCommand("INSERT TO MyTable (ImageColumn) VALUES (@Image)",MyConnacetion); InsertCommand.Parameters.Add("@Image",img); //This line throws an error MyConnection.Open(); InsertCommand.ExecutQuery(); MyConnection.Close(); When I add the paremeter, the next exception is thrown: "Index (zero based) must be greater than or equal to zero and less than the size of the argument list." Any Idea? Thanx in advance.
Answers (1)