my code is working fine, but the output shows for example 12345.000

i would like to only show the data before the .000 is this posible?

Private Sub GetCurrentJanVOL()
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            con.ConnectionString = "Data Source=" & ServerV & ";Initial Catalog=" & databaseV & ";Persist Security Info=True;User ID=" & usernameV & ";Password=" & passwordV & ""
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT SUM(QtyInvoiced) AS JanVol FROM ArTrnDetail where (Customer = '" & Me.LBCustomer.Text & "') AND (TrnYear ='" & Me.LBcurrentyear.Text & "') AND (TrnMonth = 1)"
            Dim lrd As SqlDataReader = cmd.ExecuteReader()
            While lrd.Read()

                Me.LBcurJanVol.Text = Convert.ToString(lrd("JanVol"))

            End While
        Catch ex As Exception
            MessageBox.Show("Error while getting Current year volume for Jan")
        Finally
            con.Close()
        End Try
    End Sub

Recommended Answers

All 5 Replies

Member Avatar for Unhnd_Exception

If the value from the reader "JanVol" will always be numeric:

CInt(lrd("JanVol")).ToString() 'Round up or down.
CInt(Math.Floor(lrd("JanVol"))).ToString() 'Round down.

thanks thats working fine.

thanks i thought this was sorted but it isn't as some times
the
Convert.ToString(lrd("JanVol")) is empty, when it is empty i get all kinds of errors.

is there anyway to trim the last 4 char of the string?

You can always use the Integer side for the format in a textbox

in example:

Dim p as Integer
If IsNumeric(TextBox.Text) Then
     p = Integer.Parse(TextBox.Text)
End If

that will also get take of does extra zero's

Regards,

Member Avatar for Unhnd_Exception

Validate your data from the reader.

If lrd("JanVol") Is DBNull.Value Then
      LBcurJanVol.Text = "0"
Else
      LBcurJanVol.Text = CInt(lrd("JanVol")).ToString
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.