This has me stumped so I hope someone can help.
I have an AccessDataSource bound to a DetailsView. The details view has about 8 standard BoundFields and a couple of TemplateFields with DropDownLists. On the DetailsViews OnItemUpdating event, I grab the values from the drop down’s and add the parameters to my update query using the code below.
' Insert opening time from drop downs Dim ddlBookingDayStartHour As DropDownList = MyDetailsView.FindControl("ddlBookingDayStartHour") Dim ddlBookingDayStartMin As DropDownList = MyDetailsView.FindControl("ddlBookingDayStartMin") Dim myparam As New Parameter myparam.Name = "BookingDayStart" myparam.DefaultValue = DateTime.ParseExact(ddlBookingDayStartHour.SelectedValue & ddlBookingDayStartMin.SelectedValue, "HHmm", Nothing) FacilityDetailsDataSource.UpdateParameters.Add(myparam)
But I got a data type mismatch error. So I did some testing and stripped the query back to a single field and I found that it’s getting all the parameters mixed up and associating them with the wrong fields. It appears to be ignoring the parameter names. Either that or I’m going mad.
I got this from the docs on parameter merging but it doesn’t really help.
Can anyone point me in the right direction?
I know I could build the query in the code behind but surely what I’m trying to do is possible?
Parameters are added to the DeleteParameters collection from three sources:
From the data-bound control, at run time.
From the UpdateParameters element, declaratively.
From the Updating event handler, programmatically.
First, any parameters that are generated from data-bound controls are added to the UpdateParameters collection. For example, if the ObjectDataSource control is bound to a GridView control that has the columns Name and Number, the parameters for Name and Number are added to the collection. The exact name of the parameter depends on the OldValuesParameterFormatString property. The data type of these parameters is string. Next, the parameters that are listed in the UpdateParameters element are added. If a parameter in the UpdateParameters element is found with the same name as a parameter that is already in the UpdateParameters collection, the existing parameter is modified to match the parameter that is specified in the UpdateParameters element. Typically, this is used to modify the type of the data in the parameter. Finally, you can programmatically add and remove parameters in the Updating event, which occurs before the Update method is run. The method is resolved after the parameters are merged. Method resolution is discussed in the next section.