<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>DBObject</title>
        <link>http://blogs.ugidotnet.org/soldano/category/DBObject.aspx</link>
        <description>DBObject</description>
        <language>it-IT</language>
        <copyright>Andrea SOLDANO</copyright>
        <generator>Subtext Version 2.6.0.0</generator>
        <item>
            <title>DB Object: Examples for a WebApplication</title>
            <link>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object-examples-for-a-webapplication.aspx</link>
            <description>&lt;p&gt;L'oggetto che potete scaricare nella sezione downloads non è aggiornatissimo, l'ho scritto nel 2001. &lt;/p&gt;&lt;p&gt;Prima o poi troverò il tempo per aggiornarlo. Per le applicazioni scritte con asp.net 1.1 può essere molto utile.&lt;/p&gt;&lt;p&gt;Di seguito riporto alcuni esempi di utilizzo:&lt;/p&gt;&lt;p&gt;Aggiungete nel file di configurazione il seguente codice:&lt;/p&gt;&lt;p&gt;&amp;lt;appSettings&amp;gt;&lt;br /&gt;  &amp;lt;add key="ConnectionString" value="Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=."/&amp;gt;&lt;br /&gt; &amp;lt;/appSettings&amp;gt;&lt;/p&gt;&lt;p&gt;Ecco la pagina:&lt;/p&gt;&lt;p&gt;&amp;lt;%@ Page Language="VB" %&amp;gt;&lt;br /&gt;&amp;lt;%@ Import Namespace="Esamatic.Database" %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/a&gt;"&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;script runat="server"&amp;gt;&lt;br /&gt;    Protected Sub btnOpenConnection_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpenConnection.Click&lt;br /&gt;        'Connection open using ConnetionString retrived from web.config AppSetting &lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Response.Write("Connection Open using ConnetionString retrived from web.config AppSetting .")&lt;/p&gt;&lt;p&gt;        DB.CloseDB()&lt;br /&gt;        Response.Write("Connection Close")&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;    Protected Sub btnOpenConnection1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpenConnection1.Click&lt;br /&gt;        'Connection open setting a ConnectionString&lt;br /&gt;        DB.ConnectionString = "Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=."&lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Response.Write("Connection Open setting a ConnectionString.")&lt;/p&gt;&lt;p&gt;        DB.CloseDB()&lt;br /&gt;        Response.Write("Connection Close")&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;&lt;br /&gt;    Protected Sub btnOpenConnection2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpenConnection2.Click&lt;br /&gt;        'Connection open setting a SQLConnection object&lt;br /&gt;        Dim con As New System.Data.SqlClient.SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=.")&lt;br /&gt;        DB.Connessione = con&lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Response.Write("Connection open setting a SQLConnection object.")&lt;/p&gt;&lt;p&gt;        DB.CloseDB()&lt;br /&gt;        Response.Write("Connection Close")&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;    Protected Sub btnRetriveDataset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetriveDataset.Click&lt;br /&gt;        'Retrive data into a DataSet and bind them to a GridView&lt;br /&gt;        gw.DataSource = DB.GetDataset("Select * from Customers", "Customers").Tables(0)&lt;br /&gt;        gw.DataBind()&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;    Protected Sub btnExecuteScalar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExecuteScalar.Click&lt;br /&gt;        'execute a command using ExecuteScalar&lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Response.Write("Customers count: " &amp;amp; DB.CreateCommand("SELECT count(*) From Customers").ExecuteScalar())&lt;br /&gt;        DB.CloseDB()&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;    Protected Sub btnExecuteDataReader_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExecuteDataReader.Click&lt;br /&gt;        'retrive a datareader&lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Dim dr As System.Data.IDataReader = DB.CreateCommand("SELECT top 2 * From Customers").ExecuteReader()&lt;br /&gt;        While dr.Read&lt;br /&gt;            Response.Write(dr(0) &amp;amp; "&amp;lt;br/&amp;gt;")&lt;br /&gt;        End While&lt;br /&gt;        DB.CloseDB()&lt;br /&gt;    End Sub&lt;/p&gt;&lt;p&gt;    Protected Sub btnExecuteCommandWithParameters_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExecuteCommandWithParameters.Click&lt;br /&gt;        DB.OpenDB()&lt;br /&gt;        Dim cmd As System.Data.IDbCommand = DB.CreateCommand("SELECT * From Customers where CustomerID = &lt;a href="mailto:%22%20&amp;amp;%20DB.CreateQueryParameterName(%22@CustomerID"&gt;" &amp;amp; DB.CreateQueryParameterName("@CustomerID&lt;/a&gt;"))&lt;br /&gt;        cmd.Parameters.Add(DB.CreateParameter(cmd, "CustomerID", System.Data.DbType.String, "ALFKI"))&lt;br /&gt;        Dim dr As System.Data.IDataReader = cmd.ExecuteReader()&lt;br /&gt;        While dr.Read&lt;br /&gt;            Response.Write(dr(0) &amp;amp; "&amp;lt;br/&amp;gt;")&lt;br /&gt;        End While&lt;br /&gt;        DB.CloseDB()&lt;br /&gt;    End Sub&lt;br /&gt;    &lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;html xmlns="&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;"&amp;gt;&lt;br /&gt;&amp;lt;head runat="server"&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;form id="form1" runat="server"&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnOpenConnection" runat="server" Text="Open Connection using web.config information." /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnOpenConnection1" runat="server" Text="Open Connection using setting a connection string." /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnOpenConnection2" runat="server" Text="Open Connection setting a connection object." /&amp;gt;&lt;br /&gt;        &amp;lt;hr /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnRetriveDataset" runat="server" Text="Retrive a dataset." /&amp;gt;&lt;br /&gt;        &amp;lt;asp:GridView ID="gw" runat="server" EnableViewState="false"&amp;gt;&lt;br /&gt;        &amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnExecuteScalar" runat="server" Text="Execute a scalar command" /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnExecuteDataReader" runat="server" Text="Execute a DataReader" /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID="btnExecuteCommandWithParameters" runat="server" Text="Execute a Command With Parameters" /&amp;gt;    &lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/soldano/aggbug/91606.aspx" width="1" height="1" /&gt;</description>
            <guid>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object-examples-for-a-webapplication.aspx</guid>
            <pubDate>Mon, 23 Jul 2007 13:23:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object-examples-for-a-webapplication.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/soldano/comments/commentRss/91606.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/soldano/services/trackbacks/91606.aspx</trackback:ping>
        </item>
        <item>
            <title>DB Object</title>
            <link>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object.aspx</link>
            <description>&lt;p&gt;Qualche giorno fa ho pubblicato il codice sorgente dell'oggetto &lt;a href="/files/folders/ver_1001/default.aspx" title="DB"&gt;DB&lt;/a&gt;, un componente che semplifica la comunicazione con i db.&lt;/p&gt;&lt;p&gt;Basta aggiungere la referenza all'Assembly e importatre il namespace Esamatic.Database.&lt;/p&gt;&lt;p&gt;Un esempio: con la sintassi DB.GetDatSet("Statement Sql") è possibile recuperare un dataset.&lt;/p&gt;&lt;p&gt;Per configurare la connessione al db consiglio di aggiungere la connectionString nel file di Configurazione nella sezione AppSettings, così:&lt;/p&gt;&lt;p&gt; &amp;lt;appSettings&amp;gt;&lt;br /&gt;  &amp;lt;add key="ConnectionString" value="Data Source=DBName;Initial Catalog=Database;User Id=NomeUtente;Password=password;"/&amp;gt;&lt;br /&gt; &amp;lt;/appSettings&amp;gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;img src="http://blogs.ugidotnet.org/soldano/aggbug/91605.aspx" width="1" height="1" /&gt;</description>
            <guid>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object.aspx</guid>
            <pubDate>Mon, 23 Jul 2007 13:15:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/soldano/archive/2007/07/23/db-object.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/soldano/comments/commentRss/91605.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.ugidotnet.org/soldano/services/trackbacks/91605.aspx</trackback:ping>
        </item>
    </channel>
</rss>