Stored Procedure for Insert function...

SteveoAtilla

Well-known member
Joined
Dec 22, 2004
Messages
79
Location
The Frozen Tundra
I dont know why Im not getting this, but I have a page that needs to insert a row into an SQL Server 2000 table.

I have an SQL Connection: SqlConnection1
I have a Data Adapter: SQLDataAdapter1
I have a Data Set: Accessories2
I have a Stored procedure: "InsertAccessories"

I cant figure out how to fire the Stored Procedure. It gives no errors, but also inserts no rows.

What am I missing? Heres the code:

Code:
MyCommand.CommandText = "InsertAccessories"
MyCommand.Connection = SqlConnection1
MyCommand.CommandType = CommandType.StoredProcedure

Dim P1 As New SqlParameter("@parent", SqlDbType.VarChar)
P1.Direction = ParameterDirection.Input
P1.Value = Session("EditPK")
MyCommand.Parameters.Add(P1)

Dim P2 As New SqlParameter("@child", SqlDbType.VarChar)
P2.Direction = ParameterDirection.Input
P2.Value = dgProducts.DataKeys.Item(dgProducts.SelectedItem.ItemIndex.ToString)
MyCommand.Parameters.Add(P2)

Execute the command
SqlDataAdapter1.SelectCommand = MyCommand
SqlDataAdapter1.InsertCommand.ExecuteNonQuery()

Whats missing?

Thanks,

Kahuna
 
Change the 2nd to last line
SqlDataAdapter1.SelectCommand = MyCommand

to
SqlDataAdapter1.InsertCommand = MyCommand
 
Back
Top