-
Stored Procedure Insert / Update Help
Can anyone tell me how to run a stored procedure on a SQL Server DB that is
performaing an insert or an update? I have written my stored procedure
(AddUpClient) and would like to pass it the parameter of (CompanyName) and
either a ClientID of 0 for an insert command or some corresponding ClientID
for an update. I have Stored Procedures that perform a select working
perfectly, but my Insert and Update ones are baffling me. I have been
trying several things and have copied a piece of convoluted code below. Any
help will be greatly appreciated. Thanks in advance:
'This is the sub to perform my Insert
Sub InsertClient (Source As Object, E As EventArgs)
Dim myConnection As SQLConnection
Dim myCommand As SQLDataSetCommand
Dim SQL As String
SQL = "AddUpClient"
myConnection = new
SQLConnection("server=myrlyn;uid=sa;pwd=;database=ATCallas")
myConnection.Open()
myCommand = New SQLDataSetCommand(SQL, myConnection)
myCommand.InsertCommand.CommandType = CommandType.StoredProcedure
myCommand.InsertCommand.Parameters.Add(new
SQLParameter("@CompanyName",SQLDataType.VarChar, 50))
myCommand.InsertCommand.Parameters("@CompanyName").Value
=Request.Params("CompanyName.Text").ToString()
myCommand.InsertCommand.Parameters.Add(new
SQLParameter("@ClientID",SQLDataType.Smallint, 2))
myCommand.InsertCommand.Parameters("@ClientID").Value = 0
myCommand.InsertCommand.Execute(myCommand)
myConnection.Close()
end sub
'This is the sub to perform my Update
Sub UpdateClient (Source As Object, E As EventArgs)
Dim myConnection As SQLConnection
Dim myCommand As SQLDataSetCommand
Dim SQL As String
SQL = "AddUpClient"
myConnection = new
SQLConnection("server=localhost;uid=sa;pwd=;database=ATCallas")
myCommand = New SQLDataSetCommand(SQL, myConnection)
myCommand.UpdateCommand.CommandType = CommandType.StoredProcedure
myConnection.Open()
myCommand.UpdateCommand.Parameters.Add(new SQLParameter("@CompanyName",SQ
LDataType.VarChar, 50))
myCommand.UpdateCommand.Parameters("@CompanyName").Value
=Request.Params("CompanyName.Text").ToString()
myCommand.UpdateCommand.Parameters.Add(new
SQLParameter("@ClientID",SQLDataType.Smallint, 2))
myCommand.UpdateCommand.Parameters("@ClientID").Value
=Request.Params("ClientID").ToString()
myCommand.UpdateCommand.Execute()
myConnection.Close()
End Sub
____________________________________________________
Thank You,
Jeremy
No One Important
Independent
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks