how I can insert image into sqlserver database with c#
-
how I can insert image into sqlserver database with c#.Ineed the code
-
how I can insert image into sqlserver database with c#.Ineed the code
Here you go: How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET[^]
#region signature my articles #endregion
-
how I can insert image into sqlserver database with c#.Ineed the code
Hello yemen_programmer, As far as I know, there are TWO ways to do so. 1- To store only the location of the image into your database and the image file in a different folder. 2- To store the image file as a BLOB file. The option 1 is stright forward as you only store a text into your database while your image sits in a folder. Therefore, I am going to leave that. The second option can be done with a code similar to the one here. Keep in mind that this line of code uses MySQL database and the command line "INSERT INTO ....." may be different for SQL and you need to check that out. I personaly use MySQL. The following code also includes storing other information about the stored image. But the most important one that you require is ItemImage and ImgeSize.
OdbcCom = new System.Data.Odbc.OdbcCommand("INSERT INTO item VALUES (NULL, ?, ?, ?, ?);", OdbcCon); OdbcCom.Parameters.Add("@ItemName", System.Data.Odbc.OdbcType.VarChar); OdbcCom.Parameters["@ItemName"].Value = txtItemName.Text; OdbcCom.Parameters.Add("@ItemImage", System.Data.Odbc.OdbcType.Image); OdbcCom.Parameters["@ItemImage"].Value = ImageArray; OdbcCom.Parameters.Add("@ImageSize", System.Data.Odbc.OdbcType.Int); OdbcCom.Parameters["@ImageSize"].Value = FileSize; OdbcCom.Parameters.Add("@ItemInfo", System.Data.Odbc.OdbcType.VarChar); OdbcCom.Parameters["@ItemInfo"].Value = txtItemInfo.Text; OdbcCom.ExecuteNonQuery();
Keep in mind that before being able to do so, you need to place your image in an Array which in the above code is called ImageArray. I hope that could help you out to get your image into your database. Cheers, Khoramdin -- modified at 14:49 Wednesday 21st November, 2007