|
-
Sep 25th, 2003, 09:03 AM
#1
Thread Starter
Fanatic Member
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
-
Sep 25th, 2003, 09:54 AM
#2
You should inspect the exception's message and stacktrace properties for more information on the error.
-
Sep 25th, 2003, 10:35 AM
#3
Thread Starter
Fanatic Member
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
-
Sep 25th, 2003, 11:04 AM
#4
Thread Starter
Fanatic Member
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
-
Sep 25th, 2003, 11:08 AM
#5
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:
Dim cmd As New SqlCommand("insRecord", _
New SqlConnection("Password=KJH987KJ;Persist Security Info=True;User ID=sa;Initial Catalog=MortgageFlowDev;Data Source=COSERV01\MORTGAGEFLOWLIVE"))
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"))
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.
-
Sep 26th, 2003, 10:27 AM
#6
Thread Starter
Fanatic Member
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
-
Sep 26th, 2003, 10:56 AM
#7
You can pass parameters to a stored procedure with ExecuteNonQuery.
VB Code:
Dim cmd As New SqlCommand("del_Diagnosis", _
New SqlConnection("Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=MHC_NET;Data Source=MEPHISTO"))
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@DiagnosisID", _DiagnosisID)
cmd.Parameters.Add("@AllParts", AllParts)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
cmd.Connection.Dispose()
cmd.Dispose()
-
Sep 26th, 2003, 11:46 AM
#8
Thread Starter
Fanatic Member
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
-
Sep 26th, 2003, 12:22 PM
#9
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.
-
Sep 26th, 2003, 02:07 PM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|