Click here to Skip to main content
15,908,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want save an image in database but path has pathname like
c:user\\abc\\desert.jpg and i have database name tblAbc with column name Image and datatype nvarchar(50) to store the name of path but i m not able to store the image.i dont know y to use byte array? anybody please help me with the code or anything
bishnu karki
Posted

1 solution

You can't store the image data in a 50 character string: if you can see the image, it just won't fit.
I also would not store the file path in a 50 character string - a file path can be a lot bigger than that! Make the field bigger, and store the path in it as a string.
The code is pretty much what I gave you last time, but without loading the file into a byte array first:
C#
using (SqlConnection con = new SqlConnection(connectionString))
    {
    using (SqlCommand com = new SqlCommand("INSERT INTO tblAbc ([Image]) VALUES (@IM)", con))
        {
        com.Parameters.AddWithValue("@IM", "c:user\\abc\\desert.jpg");
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900