Option Explicit On Option Strict On Imports System.Data Imports System.Data.SqlClient Public Class BranchMaintenance Private branchesDT As DataTable Private currentRowIndex As Integer Private Sub BranchMaintenance_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load 'Declare(variables) Dim connection As IDbConnection Dim command As IDbCommand Dim adapter As IDbDataAdapter 'create data set Dim branches As New DataSet 'create adapter adapter = New SqlDataAdapter 'Create SqlConnection connection = New SqlConnection("Data Source=60016P05260;Initial Catalog=Magazzino;Integrated Security=True") command = New SqlCommand 'Create Sql String with parameter @SelectedLP Dim selectAllFromBranch As String = "Select * from Articoli" 'open connection connection.Open() 'Set connection to command command.Connection = connection 'set Sql string to command object command.CommandText = selectAllFromBranch 'execute command adapter.SelectCommand = command 'fill DataSet adapter.Fill(branches) 'close connection connection.Close() Me.branchesDT = branches.Tables.Item(0) If (Me.branchesDT.Rows.Count > 0) Then currentRowIndex = 0 Dim row As DataRow = Me.branchesDT.Rows(currentRowIndex) Me.Id.Text = row.Item("Id").ToString BranchName.Text = row.Item("Articolo").ToString End If End Sub End Class |