Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27193

VS 2012 Trouble with my simple database loading and saving data

$
0
0
Hey im having an issue with my program loading and saving data. My program has 6 textboxes where you enter data and then it is added into a list box where it is then displayed.
Currently my program is giving me 3 errors :
Error Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
Error 2 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(path As String)': Argument matching parameter 'path' narrows from 'Object' to 'String'.
'Public Sub New(stream As System.IO.Stream)': Argument matching parameter 'stream' narrows from 'Object' to 'System.IO.Stream'.

all relating to these pieces of code:
Code:

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        OpenFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        SaveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
        SaveFileDialog1.ShowDialog()

    End Sub

Code:

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        Try
            Dim sr As StreamReader = New StreamReader(OpenFileDialog1.filename)
            Dim count As Integer = Integer.Parse(sr.ReadLine())
            data.Clear()
            SimpleDatabase.Items.Clear()

            Dim tempstock As Stock
            tempstock.name = sr.ReadLine()
            tempstock.catagory = sr.ReadLine()
            tempstock.location = sr.ReadLine()
            tempstock.price = sr.ReadLine()
            tempstock.order = Integer.Parse(sr.ReadLine())
            tempstock.stock = Integer.Parse(sr.ReadLine())
            data.Add(tempstock)
            SimpleDatabase.Items.Add(tempstock.name)

            sr.Close()
        Catch ex As Exception
            Console.WriteLine("the file could not be read:")
            Console.Write(ex.Message)

        End Try
    End Sub
    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Dim filetosave As String = savefiledialog1.filename
        Dim save As New System.IO.StreamWriter(filetosaveas)

        save.WriteLine(data.Count)

        Dim tempstock As Stock = data.Item(1)
        save.WriteLine(tempstock.name)
        save.WriteLine(tempstock.catagory)
        save.WriteLine(tempstock.location)
        save.WriteLine(tempstock.price)
        save.WriteLine(tempstock.order)
        save.WriteLine(tempstock.stock)

        save.Close()



    End Sub

This is a school project and my teacher is less than helpful so please anyone i need help, if it is helpful i can send a copy of the program through email and that may help as a reference.

Viewing all articles
Browse latest Browse all 27193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>