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

VS 2012 Code Optimization - Returning one row

$
0
0
Good morning everyone.

This is not a problem or a error, just a small help for code optimization.

In all of my apps, when I need to get only one value for a database (Sql compact for example or other) I use allways the same code.

I think is a big and slow code, and I'm sure that it's posisble optimize that.

I use this for example:
Code:

    Public Function CalculaDataFecho() As Date
        Dim ConexaoBD As SqlConnection
        Dim DsDados As DataSet
        Dim Dt As DataTable
        Dim Row As DataRow
        Dim DataFecho As Date
        Dim sqlString As String = "SELECT fecho FROM dbo.fecho"
        ConexaoBD = New SqlConnection(connString)
        Dim AdaptadorDados As SqlDataAdapter = New SqlDataAdapter(sqlString, ConexaoBD)
        DsDados = New DataSet()
        AdaptadorDados.Fill(DsDados, "fecho")
        Dt = DsDados.Tables("fecho")
        For Each Row In Dt.Rows
            DataFecho = Row(0)
        Next
        Return DataFecho
    End Function

How can I optimize this code, when I know the result its only one row?? For examplo check if the password is correct for a specific user.

Thank you

Viewing all articles
Browse latest Browse all 27554

Trending Articles



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