我在我的项目中使用 SqlDataSource1 控件。
源代码:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CTSConnectionString %>" SelectCommand="Vehicle" SelectCommandType="StoredProcedure" OnSelecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:Parameter Name="veh_regn_no" Type="String" />
<asp:Parameter Name="start_date" Type="DateTime" />
<asp:Parameter Name="end_date" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
后面的代码:
Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
Try
If (ddlVehicleReg.SelectedIndex > 0) AndAlso (txtStartDate.Text <> "") AndAlso (txtEndDate.Text <> "") Then
e.Command.Parameters("veh_regn_no").Value = Convert.ToString(ddlVehicleReg.SelectedValue)
e.Command.Parameters("start_date").Value = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy HH:mm:ss", Nothing)
e.Command.Parameters("end_date").Value = DateTime.ParseExact(txtEndDate.Text, "dd/MM/yyyy HH:mm:ss", Nothing)
End If
Catch ex As Exception
End Try
End Sub
我收到错误消息:
此 SqlParameterCollection 不包含具有 ParameterName 'veh_regn_no' 的 SqlParameter。
我在哪里犯了错误?