<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>grab record from db and subtracts it from variable</Title>
      <Shortcut>grabrecordfromdbandsubtractsitfromvariable</Shortcut>
      <Description>grab record from db and subtracts it from variable [VB.NET]</Description>
      <Author>Marcus Reed</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=f93231b1-c681-474b-9d41-9f9cff559d91</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="VB"><![CDATA[        Try
            ' Takes a string from the textbox to find the records source in the database
            Dim aid As String = ArrestIDToolStripTextBox.Text
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT SUM(AmountPaid) FROM tblPayment WHERE ArrestID ='" & aid & "'", con) ' SQL to pull the data from the database
            con.Open() ' open the connection to the database
            Dim amtpaid As Int32 = cmd.ExecuteScalar
            TextBox2.Text = amtpaid
            con.Close()
            Dim x1, x2 As Integer
            x1 = TextBox3.Text  ' Total Fine amount.
            x2 = TextBox2.Text  ' Total amount Paid so far.
            TextBox4.Text = Val(x1) - Val(x2) ' Subtracts the total fine amount from the amount paid to give us the total amount due.
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>