如何将参数传递给SQLDataSource

如何将参数传递给SQLDataSource

本文介绍了如何将参数传递给SQLDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经在这个问题上工作了半天,似乎无法弄清楚.

我在表单中设置了一个sqldatasource,带有2个参数以过滤记录.
我需要将参数传递给sqldatasource,以查看数据是否已经存在.

我不知道是否没有点击或我只是不了解它是如何工作的.
我是否要使用数据层,但是被告知这是一个原型,我只需要完成它即可.

任何帮助,将不胜感激.


sqldatasource

Okay, I''ve been working on this issue for half a day and can''t seem to figure it out.

I have a sqldatasource set up in my form with 2 parameters to filter the records.
I need to pass the parameters to the sqldatasource to see if the data already exist.

I don''t know if something isn''t clicking or if I''m just not understanding how this works.
I would whether use a data tier, but have been told this is a prototype and I just need to complete it.

Any help would be appreciated.


sqldatasource

<asp:SqlDataSource ID="dsAddPermission" runat="server"

                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

                    InsertCommand="proc_AddPermission"                      InsertCommandType="StoredProcedure"

                    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

                    SelectCommand="SELECT [ID], [AccountID] FROM [Permission] WHERE (([ID] = ?) AND ([AccountID] = ?))">
  <InsertParameters>
    <asp:Parameter Name="AccountID" Type="Int32" />
    <asp:Parameter Name="EmployeeID" Type="Int32" />
  </InsertParameters>
  <SelectParameters>
    <asp:Parameter Name="MyRadID" Type="Int32" />
    <asp:Parameter Name="AccountID" Type="Int32" />
  </SelectParameters>
</asp:SqlDataSource>




检索数据的代码




code to retrieve data

Private Function CheckPermissions(ByVal aID As Integer, ByVal eID As Integer) As Boolean
  Dim bCheck As Boolean
  Dim ds = New DataSet()

  ds = dsAddPermission.Select(DataSourceSelectArguments.Empty)

  If IsDBNull(ds.Tables) Then
    bCheck = False
  ElseIf ds.Tables.Count > 0 Then
    bCheck = True
  Else
    bCheck = False
  End If

  Return bCheck
End Function



[已修改:代码中的格式化选项卡]



[Modified: formatted tabs in code]

推荐答案





检索数据的代码




code to retrieve data

Private Function CheckPermissions(ByVal aID As Integer, ByVal eID As Integer) As Boolean
  Dim bCheck As Boolean
  Dim ds = New DataSet()

  ds = dsAddPermission.Select(DataSourceSelectArguments.Empty)

  If IsDBNull(ds.Tables) Then
    bCheck = False
  ElseIf ds.Tables.Count > 0 Then
    bCheck = True
  Else
    bCheck = False
  End If

  Return bCheck
End Function



[修改:代码中的格式化标签]



[Modified: formatted tabs in code]


Private Function CheckPermissions(ByVal aID As Integer, ByVal eID As Integer) As Boolean

        Dim bCheck As Boolean
        Dim dv = New DataView()

        dsAddPermission.SelectParameters("AccountID").DefaultValue = aID.ToString
        dsAddPermission.SelectParameters("MyRadID").DefaultValue = eID.ToString
        dsAddPermission.DataBind()

        dv = dsAddPermission.Select(DataSourceSelectArguments.Empty)

        If IsDBNull(dv.Table) Then
            bCheck = False
        ElseIf dv.Table.Rows.Count > 0 Then
            bCheck = True
        Else
            bCheck = False
        End If

        Return bCheck

    End Function


这篇关于如何将参数传递给SQLDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:12