Problem with multiple update

G

Guest

I am trying to create a multiple update for a datagrid! At the moment I have
the following sub which could probably be written better but I'm new to
ASP.NET and trying to get this to work first.

For some reason in the second SQL update I keep getting

...::Error
Procedure 'OfficePageUpdate' expects parameter '@ID', which was not supplied.

Even though as far as I can see it is being supplied!

Can someone please help...

Thanks!

...::CODE

Sub DGPages_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)


'Read in the values of the updated row
Dim pageID As Integer = CInt(CType(e.Item.FindControl("pageID"),
TextBox).Text)
Dim modificationDate As String =
CType(e.Item.FindControl("modificationDate"), TextBox).Text
Dim description As String = CType(e.Item.FindControl("description"),
TextBox).Text
Dim title As String = CType(e.Item.FindControl("title"), TextBox).Text
Dim strOfficeID As String =
CType(e.Item.FindControl("DDLeditOffice"), DropDownList).SelectedItem.Value


'Construct the Database Connection
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageUpdate", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

' Add Parameters to the SQL query
Dim objID, objModDate, objDescription, objTitle, objOfficeID As
SqlParameter
objID = cmd.Parameters.Add("@ID", SqlDbType.Int)
objModDate = cmd.Parameters.Add("@ModDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@Description",
SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@Title", SqlDbType.NVarChar)


objID.Direction = ParameterDirection.Input
objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input


objID.Value = pageID
objModDate.Value = modificationDate
objDescription.Value = description
objTitle.Value = title

Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()


'''''''''''''''''''''''''''''''Under Construction
'Construct the Database Connection

Dim cmd2 As New SqlCommand("OfficePageUpdate", Myconn)
cmd2.CommandType = CommandType.StoredProcedure

Myconn.Open()

objID = cmd.Parameters.Add("@ID", SqlDbType.Int)
objOfficeID = cmd.Parameters.Add("@OfficeID", SqlDbType.NVarChar)
objID.Direction = ParameterDirection.Input
objOfficeID.Direction = ParameterDirection.Input
objID.Value = pageID
objOfficeID.Value = strOfficeID

Dim myReader2 As SqlDataReader = cmd2.ExecuteReader()
myReader2.Read()
myReader2.Close()
Myconn.Close()

'''''''''''''''''''''''''''''''''End Construction

'Finally, set the EditItemIndex to -1 and rebind the DataGrid
DGPages.ShowFooter = True
DGPages.EditItemIndex = -1
BindData()
 
G

Guest

Tim,

The parameters are being added to the wrong command object in the second
instance.

Change "cmd" to "cmd2" in the following 2 lines:
objID = cmd.Parameters.Add("@ID", SqlDbType.Int)
objOfficeID = cmd.Parameters.Add("@OfficeID", SqlDbType.NVarChar)


After the change:
objID = cmd2.Parameters.Add("@ID", SqlDbType.Int)
objOfficeID = cmd2.Parameters.Add("@OfficeID", SqlDbType.NVarChar)

Cheers,
Gwynn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top