Torna al Thread

Protected Sub CollegaGrigliaCON(ByVal sender As Object, ByVal e As EventArgs) Handles BtnCollegaGriglia.Click ' questo esempio andrebbe in una apposita classe che gestisce il DATA LAYER. Poi dall'applicazione ' dovresti richiamare una ulteriore classe (il BUSINESS LAYER) che gestisce le logiche vere e proprie. ' Quest'ultima a sua volta dovrebbe richiamare i metodi e le classi che hai definito nel DATA LAYER. ' l'esempio è per sql server ' ado.net connesso Using objConn As New SqlConnection(Config.ConnectionString) objConn.Open() Using objCmd As New SqlCommand("SELECT * FROM Utenti WHERE IDUtente <= @idPassato", objConn) objCmd.Parameters.Add("@idPassato", SqlDbType.Int).Value = 10 objCmd.CommandType = CommandType.Text Try ' metodo connesso, riempio la griglia e la collego GV1.DataSource = objCmd.ExecuteReader() GV1.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Using objConn.Close() End Using End Sub Protected Sub CollegaGrigliaDIS(ByVal sender As Object, ByVal e As EventArgs) Handles BtnCollegaGrigliaDisconnesso.Click ' ado.net disconnesso Using objConn As New SqlConnection(Config.ConnectionString) objConn.Open() Using objCmd As New SqlCommand("SELECT * FROM Utenti WHERE IDUtente <= @idPassato", objConn) objCmd.Parameters.Add("@idPassato", SqlDbType.Int).Value = 10 objCmd.CommandType = CommandType.Text Using objDA As New SqlDataAdapter(objCmd) Using dt As New DataTable() ' riempio la datatable con i dati letti objDA.Fill(dt) ' riempio la griglia e la collego Try GV1.DataSource = objCmd.ExecuteReader() GV1.DataBind() Catch ex As Exception Response.Write(ex.Message) End Try End Using End Using End Using End Using End Sub Protected Sub CollegaTextBox(ByVal sender As Object, ByVal e As EventArgs) Handles BtnCollegaTextBox.Click Using objConn As New SqlConnection(Config.ConnectionString) objConn.Open() Using objCmd As New SqlCommand("SELECT TOP 1 Nome FROM Utenti ORDER BY IDUtente", objConn) objCmd.CommandType = CommandType.Text Try ' metodo connesso, riempio la griglia e la collego TxtRisultato.Text = CType(objCmd.ExecuteScalar(), String) Catch ex As Exception Response.Write(ex.Message) End Try End Using objConn.Close() End Using End Sub
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5