hi guys this is just a simple question
i want to know how to store images in database
here is my code that i used so far:
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
OpenFileDialog1.ShowDialog()
txtimg.Text = OpenFileDialog1.FileName
PictureBox1.Image = Bitmap
End Sub
Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
Dim con As New System.Data.SqlClient.SqlConnection("Data Source=ichtus\sqlexpress;Initial Catalog=PhoneBook;Integrated Security=True")
con.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand("select * from ImageTable")
cmd.Connection = con
cmd.CommandType = CommandType.Text
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
Dim bits As Byte() = CType(ds.Tables(0).Rows(0).Item(0), Byte())
Dim memorybits As New MemoryStream(bits)
Dim bitmap As New Bitmap(memorybits)
PictureBox1.Image = bitmap
End Sub
public....
Try
If Trim(txtimg.Text) = "" Then
MsgBox("Please select a image.")
Exit Sub
End If
Dim fs As New FileStream(Trim(txtimg.Text), FileMode.Open)
Dim Data() As Byte = New [Byte](fs.Length) {}
fs.Read(Data, 0, fs.Length)
Dim con As New System.Data.SqlClient.SqlConnection("Data Source=ichtus\sqlexpress;Initial Catalog=PhoneBook;Integrated Security=True")
con.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand("UploadImage")
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@Img", Data)
cmd.ExecuteNonQuery()
con.Close()
fs.Close()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
objcommand.ExecuteNonQuery()
refreshlist()
MsgBox("Contact/s has/have been added!", MsgBoxStyle.Information)
End Sub
i just tried this code i found on the net. i want the image to be displayed automatically on the picturebox but here it needs to click the download button to display the picture. how can i do this? any help would be highly appreciated