Monday, April 9, 2012

DataSet

Public Function RetornaQQCoisaAsDataSet(ByVal intID As Integer) As DataSet
        Dim str As New StringBuilder
        Dim strResultado As New StringBuilder
        Dim cmd As New SqlCommand
        Dim conn As New SqlConnection
        conn.ConnectionString = ConfigurationManager.ConnectionStrings("xxConnectionString").ConnectionString
        cmd.Connection = conn
        str.Append("  SELECT [id]  ")
        str.Append(" ,[Nome]  ")
        str.Append(" FROM [TB_XXX]  ")
        str.Append(" where id = @id ")
        cmd.CommandText = str.ToString
        cmd.Parameters.Clear()
        cmd.CommandType = CommandType.Text
        cmd.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = intID
        conn.Open()
        Dim Adapter As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        Adapter.Fill(ds)
        conn.Close()
        conn.Dispose()
        Adapter.Dispose()
        cmd.Dispose()
        Return ds
    End Function

No comments: