win from access into database

Antrac1t

Member
Joined
Apr 28, 2014
Messages
13
Programming Experience
Beginner
Hi guys,
i want to ask you if what i do is correct way (expecialy if there is no any problem about load of database or memory leaks). My program try to check units in system and base on requirements user can print some data from zebra printer. First fing is find data in database, check if was already printed if not then save this information, ore some Udt information
this is main part where i load all data
VB.NET:
Private Sub loadSNSBA()
        'nacteni zakladnich dat z DMR_SNO tabulky
        If SN_Unit.Text = "" Then
            Call MsgBox("Please write unit")
        Else
            Try
                Dim SDA As New SqlDataAdapter
                Dim dbdataset As New DataTable
                Dim bsource As New BindingSource
                conn = New SqlConnection("database connection")
                conn.Open()
                Dim Query As String
                'query 
                Query = "my query"

                Command = New SqlCommand(Query, conn)
                SDA.SelectCommand = Command
                SDA.Fill(dbdataset)
                bsource.DataSource = dbdataset
                DMR_SNO.DataSource = bsource
                SDA.Update(dbdataset)

                conn.Close()
            Catch ex As SqlException
                MessageBox.Show(ex.Message)
            Finally
                conn.Dispose()
            End Try
        End If
    End Sub

then there is part about if there is print record
VB.NET:
Private Sub CheckUnit()
Try
    conn = New SqlConnection("database connection")
    conn.Open()
    Dim checkCT As String
    'kontrola zdali bylo CT naskenovano 
    checkCT = "check query'"
     'prirazeni query 
    Command = New SqlCommand(checkCT, conn)
    'spusteni query
    Reader = Command.ExecuteReader


    Dim count As Integer = 0
    While Reader.Read
           count = count + 1
    End While
    conn.Close()
Catch ex As SqlException
    MessageBox.Show(ex.Message)
Finally
    conn.Dispose()
End Try
  
If count >= 1 Then
  error_message.Text = "already printed"
end if
End Sub


update part
VB.NET:
    Private Sub UpdateReprint()
        conn = New SqlConnection("database connection")
        Dim UpdateSeq As String
        Dim Reader As SqlDataReader
        conn.Open()
        'query  
        UpdateSeq = "update part"
        'prirazeni query 
        Command = New SqlCommand(UpdateSeq, conn)
        'spusteni query
        Reader = Command.ExecuteReader

        'save hodnot
        conn.Close()
    End Sub

then i have for example som button, textbox as trigger where i load all these things ...

thx

Antra
 
Last edited:
Top Bottom