Updating datagrid using adapter in asp - manually set parameters?

G

Guy

When updating a dataset using an adapter, do I have to manually set
the parameter values when updating a record in a dataset?

Normally I do this all manually, but I thought I'd give the data
controls a try to see if they make life easier. I've setup a web form
with a SQL Connection control, 4 SQL Command controls that I dragged
from my Stored procedure list in the server explorer, a dataset based
on one of my tables and a SQL Data adapter.

I've bound the dataset to a grid and created template columns for the
items I want to edit. The grid populates just fine, goes into edit
mode, but when I try to do the actual edit it tells me that my Sprocs
expect a parameter and is not receiving it. I as under the impression
that if the command object I dropped on the form knows about all of my
parameters, I don't have to manually set them. True?

Here's the page load and update code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
cnnSQL.ConnectionString = strConn

If Not Page.IsPostBack Then

adp.Fill(TestingData1, "Portfolio")
'store datset in cache
Session("Ports") = TestingData1
grdData.DataBind()

Else
'get dataset from session cache
TestingData1 = Session("Ports")
End If

End Sub

Private Sub grdData_UpdateCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grdData.UpdateCommand

Dim OneDataRow As TestingData.PortfolioRow

'Point to row
OneDataRow =
TestingData1.Portfolio.FindByID(grdData.DataKeys(e.Item.ItemIndex))

'change column values based on grid controls
OneDataRow.Description =
CType(e.Item.FindControl("txtDescription"), TextBox).Text
OneDataRow.GIMII_ID = CType(e.Item.FindControl("txtgimii"),
TextBox).Text
OneDataRow.Primary_Port_Co =
CType(e.Item.FindControl("txtCoord"), TextBox).Text

'call the update on my dataset
adp.Update(TestingData1.Portfolio)
'accept my changes
TestingData1.AcceptChanges()

'turn off edit mode
grdData.EditItemIndex = -1

'rebind
grdData.DataBind()
End Sub
 
G

Guy

Found answer: When I dragged and dropped my Stored Procedures onto the
form to create the command objects, the sourcecolumn field was not
filled in. I filled that in myself and now everything works.

Would have been nice to have seen that somewhere in the documentation.
 

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

Top