Torna al Thread

Public Function EseguiComando() As String ' creo il contenitore dei dati Dim ds As New DataSet("contenitore") ' messaggio di ritorno Dim Messaggio As String = String.Empty ' istanzio la connessione (devi mettere la tua connectionstring come parametro) Using conn As New SqlConnection("StringaDiConnessione") ' creo il comando basato sulla connessione Using cmd As New SqlCommand("SELECT RIS_STR_COD FROM STR_RIS WHERE RIS_NUM_ACC = '00001312'", conn) ' creo l'adattatore dei dati (per ottenere un resultset disconnesso e poter contare le righe) Using 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 End Using End Using End Using Return Messaggio End Function
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5