Click here to Skip to main content
15,887,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I need to execute a command more than one times, so i have a problem in my VB.NET loop code:

client.Connect()
Dim cmd As SshCommand
Dim result As String
cmd = client.CreateCommand("comand")

For i As Integer = 1 To 10
rezultat = cmd.Execute()
msgBox(rezultat)
Next

client.disconnect()

I figure that this command cmd.execute disconect me, so one solution is to put client.connect but I think it is not effective.

Can you help me, please....
Posted
Updated 21-Mar-14 0:30am
v2

1 solution

This is a SQL Client connectivity. So you can take an Idea of reader and implement according SshCommand.


VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If oCn.State = ConnectionState.Closed Then
            oCn.Open()
        End If

        Dim oRead As SqlClient.SqlDataReader = Nothing

        Dim cmd As New SqlClient.SqlCommand("SELECT * from mst_scheme", oCn)

        Try
            oRead = cmd.ExecuteReader
            If oRead.HasRows Then
                While oRead.Read()
                    MsgBox(oRead(0))
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            oRead.Close()
            oCn.Close()
        End Try

    End Sub
End Class
 
Share this answer
 
Comments
Amel Alić 24-Mar-14 10:59am    
I used this logic and tried but it does not work. Maybe is it problem because I make this application for CMTS.

Here is all code:


Imports Renci.SshNet

Public Class Form2

Public client As New SshClient("192.168.1.100", "root" , "admin")

Private Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
client.Disconnect()
Form1.Close()
End Sub

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
client.Connect()
End Sub

Private Sub komanda_TextChanged(sender As Object, e As EventArgs) Handles komanda.TextChanged
AcceptButton = izvrsi 'this is button's name
End Sub

Private Sub izvrsi_Click(sender As Object, e As EventArgs) Handles izvrsi.Click
If komanda.Text <> "" Then 'I have textbox (name:komanda) where i write command

Dim cmd As SshCommand
Dim result As String
cmd = client.CreateCommand(komanda.Text)
For i As Integer = 1 To 100

result = cmd.Execute()
resultText.Text = resultText.Text + result
' resultTExt is textbox
'MsgBox(result)



Next
Else
MsgBox("Write command")
End If
End Sub

End Class





When I put in loop 1 to 1 it's work but 1 to many doen't

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900