Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
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

XML
<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

VB
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]
Posted
Updated 11-Mar-11 10:34am
v3
Comments
Dalek Dave 10-Mar-11 18:27pm    
Edited for Readability. Otherwise, a good question.
milenalukic 10-Mar-11 20:02pm    
Just had a look at your profile after your comment to my question. If you're quite new to programming I would suggest you look into LINQ as it makes life much easier. I suspect any applications you build will be heavy on data so it would help to work on the database side. (Just my personal opinion here.)Sorry can't help you in web dev - I stick to windows myself.
Dalek Dave 11-Mar-11 4:08am    
Oh dear me no, that needs updating, it is nearly four years old!
Simon_Whale 11-Mar-11 11:14am    
As far as I am aware. LinQ to SQL is dependant on SQL Server. From the advise in another forum here on CP. It would be best to learn in the following order

1. SQL
2. ADO.NET
3. LINQ

As LinQ uses the underlying mechanics of ADO.NET and SQL can be used on any Database server.
William Winner 11-Mar-11 16:36pm    
How is it that you've been around here for over a year and you're not familiar with good ole Dalek Dave?

1 solution

Okay. I sat do with my boss and we figured this out. I needed to add the parameters to the datasource and then bind the data. Once I did that I was able to put the information into a view and check if a value had been returned.

We didn't change anything on the sqldatasource end, just on the function.

The following is the solution we used.

VB
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
 
Share this answer
 
Comments
fjdiewornncalwe 11-Mar-11 14:27pm    
Thanks for posting the solution. I wish everyone who figures out their problems would do that. +5 for doing that. Cheers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900