Click here to Skip to main content
15,914,405 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: RTF Pin
supercat923-May-08 13:59
supercat923-May-08 13:59 
AnswerRe: RTF Pin
The Nightcoder23-May-08 17:51
The Nightcoder23-May-08 17:51 
QuestionLive video display in vb .NET 2005/08 express Pin
Absenm22-May-08 14:17
Absenm22-May-08 14:17 
AnswerRe: Live video display in vb .NET 2005/08 express Pin
Christian Graus22-May-08 16:57
protectorChristian Graus22-May-08 16:57 
GeneralRe: Live video display in vb .NET 2005/08 express Pin
Absenm22-May-08 19:26
Absenm22-May-08 19:26 
GeneralRe: Live video display in vb .NET 2005/08 express Pin
Christian Graus22-May-08 21:20
protectorChristian Graus22-May-08 21:20 
GeneralRe: Live video display in vb .NET 2005/08 express Pin
Absenm22-May-08 22:13
Absenm22-May-08 22:13 
QuestionSQL Image Project Pin
bapu288922-May-08 9:29
bapu288922-May-08 9:29 
Hello

I have posted this problem few weeks back but still it's not been done so i am posting this again

i have create one small application in sql to save image and delete saved image from database it's works fine i can add new images to database and then i can also delete saved images from database but problem is when i add or delete image to database it dosent shows changes on screen i mean if there is 2 images in database and if i delete one image from database it deletes the image and it should shows that there is one image in database but it still shows 2 images in database but if i close the application and re start it then it shows one image in database i am totaly confuse please help me with this issue

i am pasting code for conn, add image and delete image

Private Function GetDBConnection()
       ' Compose the database file name.
       ' Modify this if the database is somewhere else.
       Dim DBname As String = Application.StartupPath()
       DBname = DBname.Substring(0, DBname.LastIndexOf("\bin"))
       DBname = DBname & "\Images.mdf"
       ' Compose the connect string.
       Dim connect_string As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & _
       DBname & ";Integrated Security=True;User Instance=True"
       ' Open a database connection.
       Dim SqlConn As New Data.SqlClient.SqlConnection(connect_string)
       SqlConn.Open()
       ' Return the connection.
       Return SqlConn
   End Function

   Private Sub LoadImages()
       dsImage.Clear()
       Try
           conImage = GetDBConnection()
           daImage.Fill(dsImage, "Images")
       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
       conImage.Close()
       conImage.Dispose()
       Call PoChng()
   End Sub

   Private Sub PoChng()
       If Me.ImagesBindingSource.Count = 0 Then
           Label1.Text = "Empty Database"
       Else
           Label1.Text = (Me.ImagesBindingSource.Position + 1).ToString & "  Of  " & _
           (Me.ImagesBindingSource.Count).ToString
       End If
   End Sub

 Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
       picImage.Image = Nothing
       txtImageFile.Text = ""
       txtTitle.Text = ""
       OpenFileDialog1.ShowDialog()
       Dim sFilePath As String
       sFilePath = OpenFileDialog1.FileName
       If sFilePath = "" Then Exit Sub

       If System.IO.File.Exists(sFilePath) = False Then
           Exit Sub
       Else
           txtImageFile.Text = sFilePath
           mImageFilePath = sFilePath
       End If
   End Sub
   Private Sub GetImage()
       Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open)
       Dim img As Byte() = New Byte(fs.Length) {}
       fs.Read(img, 0, fs.Length)
       fs.Close()
       mImageFile = Image.FromFile(mImageFilePath.ToString())
       Dim imgHeight As Integer = mImageFile.Height
       Dim imgWidth As Integer = mImageFile.Width
       Dim imgLength As Integer = mImageFile.PropertyItems.Length
       Dim imgType As String = Path.GetExtension(mImageFilePath)
       mImageFile = Nothing
       ' image content
       Dim pic As SqlParameter = New SqlParameter("@pic", SqlDbType.Image)
       pic.Value = img
       commImage.Parameters.Add(pic)

       ' title
       Dim title As SqlParameter = New SqlParameter("@title", System.Data.SqlDbType.VarChar, 50)
       title.Value = txtTitle.Text.ToString()
       commImage.Parameters.Add(title)

       ' type
       Dim itype As SqlParameter = New SqlParameter("@itype", System.Data.SqlDbType.Char, 4)
       itype.Value = imgType.ToString()
       commImage.Parameters.Add(itype)

       ' height
       Dim iheight As SqlParameter = New SqlParameter("@iheight", System.Data.SqlDbType.Int)
       iheight.Value = imgHeight
       commImage.Parameters.Add(iheight)

       ' width
       Dim iwidth As SqlParameter = New SqlParameter("@iwidth", System.Data.SqlDbType.Int)
       iwidth.Value = imgWidth
       commImage.Parameters.Add(iwidth)
   End Sub
   Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

       'get sql connection
       Try
           conImage = GetDBConnection()
           Dim sSQL As String = "INSERT INTO Images (Pic,Title, IType, Height, Width) VALUES(" & _
                          "@pic, @title, @itype, @iheight, @iwidth)"
           commImage = New Data.SqlClient.SqlCommand(sSQL, conImage)
           Call GetImage()
           commImage.ExecuteNonQuery()
           MessageBox.Show("Image successfuly saved in database", "Image Load")
       Catch ex As Exception
           MsgBox(ex.Message)

       End Try
       commImage.Dispose()
       commImage = Nothing
       conImage.Close()
       conImage.Dispose()
       Call LoadImages()
   End Sub


please help

waiting for your kind rep.

have a nice day

thank you
AnswerRe: SQL Image Project Pin
Christian Graus22-May-08 16:44
protectorChristian Graus22-May-08 16:44 
QuestionUpdate/change Database field... Pin
CCG322-May-08 9:11
CCG322-May-08 9:11 
AnswerRe: Update/change Database field... Pin
jzonthemtn22-May-08 16:46
jzonthemtn22-May-08 16:46 
QuestionAlternate background color for column with TableStyle / GridColumnStyle Pin
Johan Hakkesteegt22-May-08 7:57
Johan Hakkesteegt22-May-08 7:57 
AnswerRe: Alternate background color for column with TableStyle / GridColumnStyle Pin
Smithers-Jones22-May-08 12:08
Smithers-Jones22-May-08 12:08 
GeneralRe: Alternate background color for column with TableStyle / GridColumnStyle Pin
Johan Hakkesteegt23-May-08 0:02
Johan Hakkesteegt23-May-08 0:02 
QuestionError using GetPrivateProfileString and GetPrivateProfileSectionNames Pin
DQNOK22-May-08 5:43
professionalDQNOK22-May-08 5:43 
QuestionZooming to a doubleclicked point in a picturebox Pin
bigbird7022-May-08 5:10
bigbird7022-May-08 5:10 
AnswerRe: Zooming to a doubleclicked point in a picturebox Pin
jzonthemtn22-May-08 16:38
jzonthemtn22-May-08 16:38 
GeneralRe: Zooming to a doubleclicked point in a picturebox Pin
bigbird7022-May-08 21:27
bigbird7022-May-08 21:27 
QuestionUnable to generate a temporary class (result=1). Pin
C.Shivashankar22-May-08 3:39
C.Shivashankar22-May-08 3:39 
AnswerRe: Unable to generate a temporary class (result=1). Pin
Member 9020303-Nov-09 19:55
Member 9020303-Nov-09 19:55 
QuestionAnyone know a solution? Pin
farzadmf22-May-08 2:39
farzadmf22-May-08 2:39 
AnswerRe: Anyone know a solution? Pin
Christian Graus22-May-08 2:48
protectorChristian Graus22-May-08 2:48 
QuestionTimeDate..... Pin
Subjugate22-May-08 0:03
Subjugate22-May-08 0:03 
AnswerRe: TimeDate..... Pin
helelark12322-May-08 0:15
helelark12322-May-08 0:15 
GeneralRe: TimeDate..... Pin
Subjugate22-May-08 2:36
Subjugate22-May-08 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.