sql image problem
-
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.SqlTypesPublic 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()
-
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.SqlTypesPublic 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()
-
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
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 Suband 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