Results 1 to 10 of 10

Thread: passing paramiters to sp's

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    passing paramiters to sp's

    Can you help me im totally lost

    I have a stored procedure simple Insert one that works fine because ive tested it with query a
    ------------------------------------------------------------------------------

    Create Procedure InsRecord

    @RecordId int Output,
    @strTitle nvarchar(4),
    @strFirstName nvarchar(50),
    @strSurname nvarchar(50)
    AS

    Set NoCount On

    Declare @IntErrorCode Int
    Select @intErrorCode = @@error

    If @intErrorCode = 0
    Begin

    Insert into TelesalesData(Title,firstName,Surname)Values(@strTitle,@strFirstName,@strSurname)
    Select @intErrorCode = @@Error,
    @RecordId = @@Identity
    End
    Return @IntErrorCode


    GO
    -----------------------------------------------------------------------------
    However im having major problems

    is this the standard way to pass stuff to a stored proc

    Dim cn As New SqlConnection("Password=blah;Persist Security Info=True;User ID=blah;Initial Catalog=blah;Data Source=blah")
    Dim cmd As New SqlCommand("insRecord")
    cmd.Connection = cn
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(New SqlParameter("@strTitle", "Mr"))
    cmd.Parameters.Add(New SqlParameter("@strFirstName", "wolly"))
    cmd.Parameters.Add(New SqlParameter("@strSurname", "woo"))
    cmd.Connection.Open()
    cmd.ExecuteNonQuery()

    if not then what is the standard way to deal with SP's ?

    cheers in advance
    -------------------------------------------------------------------------------------
    ps all i get is this

    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

    Additional information: System error.
    Last edited by carlblanchard; Sep 25th, 2003 at 11:00 AM.
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should inspect the exception's message and stacktrace properties for more information on the error.

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    So is the code right then ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  4. #4

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    found this

    http://www.dotnet247.com/247referenc...;EN-US;Q310368

    whats your opinon im not at work no more so cant test till tomorrow
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Looks fine to me or atleast nothing 'seems' out of place. I'd save myself some typing when creating the command but that is strictly personal.
    VB Code:
    1. Dim cmd As New SqlCommand("insRecord", _
    2. New SqlConnection("Password=KJH987KJ;Persist Security Info=True;User ID=sa;Initial Catalog=MortgageFlowDev;Data Source=COSERV01\MORTGAGEFLOWLIVE"))
    3. cmd.CommandType = CommandType.StoredProcedure
    4. cmd.Parameters.Add(New SqlParameter("@strTitle", "Mr"))
    5. cmd.Parameters.Add(New SqlParameter("@strFirstName", "wolly"))
    6. cmd.Parameters.Add(New SqlParameter("@strSurname", "woo"))

    Are you using SQL7 and I think that articles is relative to the Prepare method. Actually if you want to make life easier then you should check out the MS Data Access Blocks.

    http://msdn.microsoft.com/library/de...ml/daab-rm.asp

    It is basically a set of wrapper type classes that simplify the process.
    Last edited by Edneeis; Sep 25th, 2003 at 11:14 AM.

  6. #6

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    aaaaaaaaaaggggggggghhhhhhhhhh

    How do u action the command

    executeNonQuery dosnt allow passing of parameters to a stored proc

    HAS ANYONE GOT A THE VB CODE FOR INSERTING, UPDATING, DELETING by use with stored procs
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can pass parameters to a stored procedure with ExecuteNonQuery.
    VB Code:
    1. Dim cmd As New SqlCommand("del_Diagnosis", _
    2.         New SqlConnection("Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=MHC_NET;Data Source=MEPHISTO"))
    3.         cmd.CommandType = CommandType.StoredProcedure
    4.         cmd.Parameters.Add("@DiagnosisID", _DiagnosisID)
    5.         cmd.Parameters.Add("@AllParts", AllParts)
    6.         cmd.Connection.Open()
    7.         cmd.ExecuteNonQuery()
    8.         cmd.Connection.Close()
    9.         cmd.Connection.Dispose()
    10.         cmd.Dispose()

  8. #8

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Thanks for putting me right on that msdn is confusing to read sometimes......

    Why im i getting system error all the time ?

    i stuck the executeNonQuery in try catch end try to get more of the error than just system.error (dam u microsoft) and this is what i got

    System.Data.SqlClient.SqlException: The request for procedure 'TrustedUsers' failed because 'TrustedUsers' is a table object.
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at SQLexecuteNonQuery.Form1.Button1_Click(Object sender, EventArgs e) in C:\Katiya Hosting\Internal Software\SQLexecuteNonQuery\Form1.vb:line 67

    any comments
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Where does 'TrustedUsers' come in? Is that in your SP? I don't know it kinda sounds like your SP tries to use a User Function named TrustedUsers and there is a table named TrustedUsers and its getting confused but thats just a guess. Without knowing what TrustedUsers is I can't tell you. It could also be some sort of SQL Security issue.

  10. #10

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    at long last

    Hey THANKS LOADS MAN

    at last it works Yes i struck the table name in by mistake DOH

    ONCE AGAIN THANKS FOR YOUR HELP
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width