Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. sql image problem

sql image problem

Scheduled Pinned Locked Moved Database
helpdatabasequestioncsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bapu2889
    wrote on last edited by
    #1

    hi i am new in vb.net and now i am learning sql and i have create one small application with sql and in table there are two columns one is imageID and second one is Image i can save and delete image with sql database but problme is when i add or delete image is dosent shows changes i mean if i add second image in to database but it still shows there is one image in database but if i close application and re run it then it shows there is two images in database so i am not sure but it looks like i need to refresh some thing but i dont know what is it possible to help me with this issue ? this is my code

    Imports System.IO
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Data.SqlTypes

    Public Class Form1

    Private mImageFile As Image
    Private mImageFilePath As String
    Dim CurrentImage As Integer
    Dim SelectedImage As String
    Dim Img As String
    
    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 MoNext()
        Me.BindingContext(dsImage, "Images").Position = Me.BindingContext(dsImage, "Images").Position + 1
        Me.ImagesBindingSource.Position = Me.ImagesBindingSource.Position + 1
        Call PoChng()
    End Sub
    Private Sub MoPre()
    
    A 1 Reply Last reply
    0
    • B bapu2889

      hi i am new in vb.net and now i am learning sql and i have create one small application with sql and in table there are two columns one is imageID and second one is Image i can save and delete image with sql database but problme is when i add or delete image is dosent shows changes i mean if i add second image in to database but it still shows there is one image in database but if i close application and re run it then it shows there is two images in database so i am not sure but it looks like i need to refresh some thing but i dont know what is it possible to help me with this issue ? this is my code

      Imports System.IO
      Imports System.Data
      Imports System.Data.SqlClient
      Imports System.Data.SqlTypes

      Public Class Form1

      Private mImageFile As Image
      Private mImageFilePath As String
      Dim CurrentImage As Integer
      Dim SelectedImage As String
      Dim Img As String
      
      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 MoNext()
          Me.BindingContext(dsImage, "Images").Position = Me.BindingContext(dsImage, "Images").Position + 1
          Me.ImagesBindingSource.Position = Me.ImagesBindingSource.Position + 1
          Call PoChng()
      End Sub
      Private Sub MoPre()
      
      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      I'm not sure, but I think somewhere along the line in FillImages you need to rebind your datasource (Me.ImagesBindingSource). Hope this helps

      Bob Ashfield Consultants Ltd

      B 1 Reply Last reply
      0
      • A Ashfield

        I'm not sure, but I think somewhere along the line in FillImages you need to rebind your datasource (Me.ImagesBindingSource). Hope this helps

        Bob Ashfield Consultants Ltd

        B Offline
        B Offline
        bapu2889
        wrote on last edited by
        #3

        Hello sir First of all thanks for your kind rep. as you said i have tried but still same problem so i dont know what to do now this is what i have done

        Private Sub LoadImages()
        dsImage.Clear()
        Try
        conImage = GetDBConnection()
        daImage.Fill(dsImage.Images)
        Me.ImagesBindingSource.ResetCurrentItem()
        Catch ex As Exception
        MsgBox(ex.Message)
        End Try
        conImage.Close()
        conImage.Dispose()
        Me.ImagesBindingSource.ResetBindings(True)
        Call PoChng()
        End Sub

        and i have also try to put this bold and underline code in several different place but it's not doing any thing :confused: so could you please tell me what to do now waiting for your kind rep. have a nice day

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups