Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Executing Stored Procs With Params
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
00979533
Message ID:
00979768
Vues:
21
Wow, your up late

The message is:

"An unhandled exception of the type 'System.Data.SqlClient.SqlException'
occure din microsoft.visualbasic.dll

Additional information: System Error.


I'm calling a SP I created to get a customer record
from Northwind!Customer, passing Country and PostalCode.

Here's my stored proc
CREATE PROCEDURE dbo.sp_GetCustomer
    @Country nvarchar(10),
    @PostalCode nvarchar(10)
    
AS
BEGIN
    SELECT *
    FROM
        Customers
    WHERE
        Country = @Country and
	PostalCode = @PostalCode
END
GO
<pre>


The test program's code:
<pre>
Dim aSqlParms = New ArrayList
aSqlParms.Add(New SqlParameter("@Country", "France"))
aSqlParms.Add(New SqlParameter("@PostalCode", "67000"))

Stuff.StoredProcExample2("sp_GetCustomer", "Customers", aSqlParms)
And the code to call the SP:
    Public Sub StoredProcExample2(ByVal sProcName As String, ByVal sTable As String, ByRef aParameters As ArrayList)

        ' Create a new Connection
        Dim oConnection As SqlConnection
        oConnection = New SqlConnection("data source=(local);initial catalog=Northwind; user id=kevin; password=googler1")
        oConnection.Open()

        Dim oDataSet = New DataSet

        Dim oSqlAdapter = New SqlDataAdapter(sProcName, oConnection)

        oSqlAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

        Dim oParms As New SqlParameter
        For Each oParms In aParameters

            oSqlAdapter.SelectCommand.Parameters.Add(oParms)

        Next

        Dim iRowCount As Integer
        iRowCount = oSqlAdapter.Fill(oDataSet, sTable)
        MsgBox(iRowCount)

        Dim oDataRow As DataRow
        Dim sString As String

        For Each oDataRow In oDataSet.Tables(sTable).Rows

            sString = sString & oDataRow("CustomerId") & ControlChars.CrLf & _
            sString = sString & oDataRow("CompanyName") & ControlChars.CrLf & _
            sString = sString & oDataRow("Country") & ControlChars.CrLf & _
            sString = sString & oDataRow("PostalCode")

            MsgBox(sString)

            sString = ""
        Next

        oConnection.Close()

    End Sub
>Kevin,
>
>In addition to "system error", was there any additional information provided?
>
>Check that your SQL stored procedure has two paraemters that are spelled exactly the same, that both are expected a character type, etc. Again, there should have been some additional information to go along with "system error".
>
>Kevin
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform