Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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
[2701 byte] By [Jeremy Samkowiak] at [2007-11-9 16:24:20]