现在的位置: 首页 > 综合 > 正文

VB.NET操作SQL Server完全模块

2012年10月14日 ⁄ 综合 ⁄ 共 1943字 ⁄ 字号 评论关闭

VB.NET操作SQL Server完全模块

Module ModSql

    Function GetIntByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As Integer

 

        Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

 

        Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where  " & ParaName & "='" & ParaValue & "'"

        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

 

        Dim rowsAffected As Integer = 0

        sqlConnection.Open()

        Try

            rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

        Catch ex As Exception

            Throw New NotSupportedException(ex.Message)

        Finally

            sqlConnection.Close()

        End Try

 

        Return rowsAffected

 

    End Function

 

    Function GetIntByInt(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As Integer

 

        Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

 

        Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where  " & ParaName & "=" & ParaValue & ""

        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

 

        Dim rowsAffected As Integer = 0

        sqlConnection.Open()

        Try

            rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

        Catch ex As Exception

            Throw New NotSupportedException(ex.Message)

        Finally

            sqlConnection.Close()

        End Try

 

        Return rowsAffected

    End Function

 

    Function GetStrByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As String

 

        Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

 

        Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where  " & ParaName & "='" & ParaValue & "'"

        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

 

        Dim

抱歉!评论已关闭.