Click here to Skip to main content
15,892,059 members
Home / Discussions / Database
   

Database

 
QuestionReporting Services - Reports Pin
john349-Jun-08 6:38
john349-Jun-08 6:38 
AnswerRe: Reporting Services - Reports Pin
DerekFL9-Jun-08 6:52
DerekFL9-Jun-08 6:52 
GeneralRe: Reporting Services - Reports Pin
john349-Jun-08 22:36
john349-Jun-08 22:36 
GeneralRe: Reporting Services - Reports Pin
john3410-Jun-08 1:07
john3410-Jun-08 1:07 
QuestionFormatting XML in SQL 2005 to include version Pin
DerekFL9-Jun-08 6:23
DerekFL9-Jun-08 6:23 
QuestionThe Top n Keyword [modified] Pin
Behzad Ordubadi9-Jun-08 5:02
professionalBehzad Ordubadi9-Jun-08 5:02 
QuestionProblem with SSRS 2005 using forms authentication while integration with Web Apps Pin
Jeff_Bennet9-Jun-08 2:25
Jeff_Bennet9-Jun-08 2:25 
Questionsql image problem Pin
bapu28898-Jun-08 6:58
bapu28898-Jun-08 6:58 
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()
        Me.BindingContext(dsImage, "Images").Position = Me.BindingContext(dsImage, "Images").Position + 1
        Me.ImagesBindingSource.Position = Me.ImagesBindingSource.Position - 1
        Call PoChng()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.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 = picImage.Height 'mImageFile.Height
        Dim imgWidth As Integer = picImage.Width '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)

    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click


        'get sql connection
        Try
            conImage = GetDBConnection()
            Dim sSQL As String = "INSERT INTO Images (Pic) VALUES(@pic)"
            commImage = New Data.SqlClient.SqlCommand(sSQL, conImage)
            Call GetImage()
            commImage.ExecuteNonQuery()
            'Me.ImagesTableAdapter.Update(Me.dsImage.Images)
            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

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        SelectedImage = ("DELETE FROM Images WHERE ImageID = " & txtImageFile.Text)
        conImage = GetDBConnection()
        Try
            commImage = New Data.SqlClient.SqlCommand(SelectedImage, conImage)
            commImage.ExecuteNonQuery()
            '  Me.ImagesTableAdapter.Update(Me.dsImage.Images)

            MsgBox("Image successfuly deleted from database", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        commImage.Dispose()
        commImage = Nothing
        conImage.Close()
        conImage.Dispose()
        Call LoadImages()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call LoadImages()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call MoPre()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call MoNext()
    End Sub
Confused | :confused:

i have drag and drop these
sql adapetr
sql connection
sql command
i have no problem with save and delete and i dont know which part of code do i need to post so i am posting all code here

waiting for your kind rep.

have a nice day

thank you
AnswerRe: sql image problem Pin
Ashfield9-Jun-08 21:18
Ashfield9-Jun-08 21:18 
QuestionRe: sql image problem Pin
bapu288910-Jun-08 9:44
bapu288910-Jun-08 9:44 
QuestionSQL Server 2000 Installation Pin
Software_Guy_1237-Jun-08 21:01
Software_Guy_1237-Jun-08 21:01 
AnswerRe: SQL Server 2000 Installation Pin
Zoltan Balazs8-Jun-08 0:36
Zoltan Balazs8-Jun-08 0:36 
QuestionSQL Server 2005 Error 26. Any Ideas please. Pin
KrisnNala7-Jun-08 8:40
KrisnNala7-Jun-08 8:40 
AnswerRe: SQL Server 2005 Error 26. Any Ideas please. Pin
Parwej Ahamad7-Jun-08 8:48
professionalParwej Ahamad7-Jun-08 8:48 
GeneralRe: SQL Server 2005 Error 26. Any Ideas please. Pin
KrisnNala7-Jun-08 9:28
KrisnNala7-Jun-08 9:28 
GeneralRe: SQL Server 2005 Error 26. Any Ideas please. Pin
Alsvha7-Jun-08 19:59
Alsvha7-Jun-08 19:59 
GeneralRe: SQL Server 2005 Error 26. Any Ideas please. Pin
KrisnNala7-Jun-08 22:16
KrisnNala7-Jun-08 22:16 
Questionneed your help! Pin
meki_21187-Jun-08 7:25
meki_21187-Jun-08 7:25 
AnswerRe: need your help! [modified] Pin
Parwej Ahamad7-Jun-08 7:40
professionalParwej Ahamad7-Jun-08 7:40 
GeneralRe: need your help! Pin
meki_21187-Jun-08 8:02
meki_21187-Jun-08 8:02 
GeneralRe: need your help! Pin
Alsvha7-Jun-08 8:06
Alsvha7-Jun-08 8:06 
GeneralRe: need your help! Pin
meki_21187-Jun-08 8:29
meki_21187-Jun-08 8:29 
GeneralRe: need your help! Pin
Parwej Ahamad7-Jun-08 8:09
professionalParwej Ahamad7-Jun-08 8:09 
GeneralRe: need your help! Pin
meki_21187-Jun-08 8:19
meki_21187-Jun-08 8:19 
GeneralRe: need your help! Pin
Parwej Ahamad7-Jun-08 8:23
professionalParwej Ahamad7-Jun-08 8:23 

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.