Torna al Thread

public static DataSet callStored(string Table, string nameStoreProcedure, SqlParameter[] parametri) { HttpContext _Content= HttpContext.Current; SqlConnection connessione = new SqlConnection("stringa di connessione"); DataSet ds = new DataSet(); try { connessione.Open(); SqlCommand command = new SqlCommand(nameStoreProcedure, connessione); SqlDataAdapter adapter = new SqlDataAdapter(); command.CommandType = CommandType.StoredProcedure; if (parametri != null) { for (int i = 0; i < parametri.Length - 1; i++) { if (parametri[i].Value == null) { command.Parameters.Add(parametri[i]); command.Parameters[i].Value = System.DBNull.Value; } else command.Parameters.Add(parametri[i]); try { System.Xml.XmlAttribute valore; valore = (System.Xml.XmlAttribute)command.Parameters[i].Value; if (valore.InnerText == "DBNull") command.Parameters[i].Value = System.DBNull.Value; } catch { } } } adapter.SelectCommand = command; if (Table == null) adapter.Fill(ds, "default"); else adapter.Fill(ds, Table); } catch { } finally { connessione.Close(); } return ds; }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5