Jump to content
dipacheco

é possivel fazer um reader dentro d um reader??

Recommended Posts

dipacheco

command = New SqlCommand("SELECT * FROM Prod WHERE Dataproxdia<='" & dia & "' AND Dataproxmes<='" & mes & "' AND Dataproxano<='" & ano & "'", connect)
        reader = command.ExecuteReader
        While reader.Read
            cliente = reader(0)
            produto = reader(1).ToString
            quantidade = reader(2)
            valor = reader(3).ToString
        End While
        reader.Close()

Tenho o código acima... e quero saber se posso fazer o código abaixo...

command = New SqlCommand("SELECT * FROM Prod WHERE Dataproxdia<='" & dia & "' AND Dataproxmes<='" & mes & "' AND Dataproxano<='" & ano & "'", connect)
        reader = command.ExecuteReader
        While reader.Read
            cliente = reader(0)
            produto = reader(1).ToString
            quantidade = reader(2)
            valor = reader(3).ToString
            command2 = new sqlcommand("SELECT Nome1,Nome2 FROM Clientes WHERE Codigo='" & cliente & "'", connect)
            reader2 = command2.executereader
            while reader2.read
                 ...........
            end while
            reader2.close
        End While
        reader.Close()

Share this post


Link to post
Share on other sites
dipacheco

abrir uma nova connection mesmo q a connection string seja exatamente a mesma?

Share this post


Link to post
Share on other sites
dipacheco

ha maneira de fazer um update em q some valores aos q já estao na tabela??? com os parameters...

exemplo, se quero adicionar 20 o que coloco nos ??????????

updater = "UPDATE [Tabela] SET [Conta]=@Conta"

command.Parameters.AddWithValue("@Conta", ???????????)

command.executereader

Share this post


Link to post
Share on other sites
Rechousa

Pelo que percebi queres adicionar um determinado valor (exemplo 20) ao campo Conta, é isso?

Imaginando que o campo Conta contém o valor 200, irá ficar com 220 (à partida :-))

updater = "UPDATE [Tabela] SET [Conta]=[Conta] + @Conta"
command.Parameters.AddWithValue("@Conta", 20)
command.executereader


Pedro Martins

Sharing is Knowledge!

http://www.linkedin.com/in/rechousa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.