I have a picturebox from which the image will be stored and the name of the image will also be stored(it is for the reference of the image). then based on the name of the image given by the textbox, the image should be displayed.

but in sql the image path is only stored how to store the image as it is.

有帮助吗?

解决方案

in sql the type of image is image. now follow the below code

        cmd = New SqlCommand("INSERT INTO image VALUES(@name,@photo)", conn)
        cmd.Parameters.AddWithValue("@name", TextBox1.Text)
        Dim ms As New MemoryStream()
        PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
        Dim data As Byte() = ms.GetBuffer()
        Dim p As New SqlParameter("@photo", SqlDbType.Image)
        p.Value = data
        cmd.Parameters.Add(p)
        cmd.ExecuteNonQuery()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top