Torna al Thread

Public Function EseguiComando() As String ' messaggio di ritorno Dim Messaggio As String = String.Empty ' istanzio la connessione (devi mettere la tua connectionstring come parametro) Dim conn As New OleDbConnection("StringaDiConnessione") ' creo il comando basato sulla connessione Dim cmd As New OleDbCommand("SELECT RIS_STR_COD FROM STR_RIS WHERE RIS_NUM_ACC = '00001312'", conn) ' creo il contenitore dei dati Dim ds As New DataSet("contenitore") ' creo l'adattatore dei dati (per ottenere un resultset disconnesso e poter contare le righe) Dim da As New OleDbDataAdapter(cmd) Try conn.Open() ' riempio il contenitore (dataset) da.Fill(ds) ' se ho almeno una tabella nel dataset stampo il creo il messaggio col numero di righe If ds.Tables.Count > 0 Then Messaggio = String.Format("Comando eseguito correttamente, numero di righe ottenute: {0}", ds.Tables(0).Rows.Count) End If Catch ex As Exception Messaggio = String.Format("Errore {0} - {1}", ex.Source, ex.Message) Finally ' chiudo comunque la connessione If Not conn.State = ConnectionState.Closed Then conn.Close() End Try Return Messaggio End Function
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5