Friday, February 24, 2012

Inserting Records via Stored Procedure

I am trying to insert a record in a SQL2005 Express database. I can use the sp fine and it works inside of the database, but when I try to launch it via ASP.NET it fails...

here is the code. I realize it is not complete, but the only required field is defined via hard code. The error I am getting states it cannot find "sp_InserOrder"

===

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Dim connAs SqlConnection =Nothing

Dim transAs SqlTransaction =Nothing

Dim cmdAs SqlCommand

conn =New SqlConnection(ConfigurationManager.ConnectionStrings("PartsConnectionString").ConnectionString)

conn.Open()

trans = conn.BeginTransaction

cmd =New SqlCommand()

cmd.Connection = conn

cmd.Transaction = trans

cmd.CommandText ="usp_InserOrder"

cmd.CommandType = Data.CommandType.StoredProcedure

cmd.Parameters.Add("@.MaterialID", Data.SqlDbType.Int)

cmd.Parameters.Add("@.OpenItem", Data.SqlDbType.Bit)

cmd.Parameters("@.MaterialID").Value = 3

cmd.ExecuteNonQuery()

trans.Commit()

=====

I get an error stating cannot find stored procedure. I added the Network Service account full access to the Web Site Directory, which is currently running locally on Windows XP Pro SP2.

Please help, I am a newb and lost...as you can tell from my code...

Are you absolutely sure that your stored procedure is called usp_InserOrder. It would make more sense if it was called usp_InsertOrder.|||It is called that. That is what I was thinking at firs, but I checked the database and that is what I named it.|||

I ran it inside of SQL 2005 here is the output...

(0 row(s) returned)

@.RETURN_VALUE = 0

Finished running [dbo].[InserOrder].

|||You code should read -cmd.CommandText ="InserOrder" as that is what it is called in the report you posted above.

No comments:

Post a Comment