Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello my question is how to insert image to sqlserver 2005 using vb.net 2008 , my Table name is Image_tbl, and Fields are (Image_ID and Photos) in image_ID field i am storing name of picture and In Photos Field i want to store image. So my code is working but only image name is sstoring but photos are not and in the photos field showing text of 'binary data'... so i need your help ,need simple code for this.And my code Is:
VB
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
    Dim cn As New SqlConnection("Data Source=NIDA-PC\SQLEXPRESS;Initial Catalog=Finaldb;Integrated Security=True")
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim ms As New MemoryStream
    Dim cmd As New SqlCommand
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
            
        End If
    End Sub
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub
    Dim n As Integer
    Dim Photo_aray As Byte
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        cn.Open()
        cmd.CommandText = "Insert into Image_tbl(Image_ID,Photos)Values('" & TextBox1.Text & "','" & OpenFileDialog1.FileName & "')"
        cmd.Connection = cn
        Int(n = cmd.ExecuteNonQuery())
        MsgBox("insert Image successfully")
        cn.Close()

      
    End Sub
End Class
Posted
Updated 30-May-14 3:09am
v2

 
Share this answer
 
me also using this code but this is not working properly ...
 
Share this answer
 
Comments
Member 10853731 30-May-14 3:40am    
me also using this code but this is not working properly...
Member 10853731 2-Jun-14 4:27am    
Anybody for help me ?

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