Blog di Andrea Soldano

"I have a dream ..."
posts - 53, comments - 263, trackbacks - 18

My Links

News








Tag Cloud

Archives

Post Categories

I miei siti

Gli errori del sito Microsoft ...

Sul sito Microsft potete trovare un  bellissimo esempio di Stored Procedure scritta con codice Managed (CLR). 

Bello l'esempio, per carità. Se però il codice fosse corretto sarebbe meglio .... :)

Di seguito una versione rivista e corretta. Ho evidenziato in neretto gli errori banali.

-- Codice di esempio 1

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class StoredProcedures

    <SqlProcedure()> _
    Public Shared Sub InsertCurrency( _
        ByVal currencyCode As SqlString, ByVal name As SqlString)

        Using conn As New SqlConnection("context connection=true")

            Dim InsertCurrencyCommand As New SqlCommand()
            Dim currencyCodeParam As New SqlParameter("@CurrencyCode", SqlDbType.NVarChar)
            Dim nameParam As New SqlParameter("@Name", SqlDbType.NVarChar)

            currencyCodeParam.Value = currencyCode
            nameParam.Value = name

InsertCurrencyCommand.Parameters.add(currencyCodeParam)

InsertCurrencyCommand.Parameters.add(nameParam)


            InsertCurrencyCommand.CommandText = _
                "INSERT Sales.Currency (CurrencyCode, Name)" & _
                " VALUES(@CurrencyCode, @Name)"

            InsertCurrencyCommand.Connection = conn

            conn.Open()
            InsertCurrencyCommand.ExecuteNonQuery()
            conn.Close()
        End Using
    End Sub
End Class

--- esempio 2

EXEC InsertCurrency 'AAA', 'Currency Test'
SELECT * from Sales.Currency where CurrencyCode = 'AAA'

Print | posted on venerdì 16 marzo 2007 01:22 |

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET