Click here to Skip to main content
15,310,017 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.


<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] = ?))">
    <asp:Parameter Name="AccountID" Type="Int32" />
    <asp:Parameter Name="EmployeeID" Type="Int32" />
    <asp:Parameter Name="MyRadID" Type="Int32" />
    <asp:Parameter Name="AccountID" Type="Int32" />

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
    bCheck = False
  End If

  Return bCheck
End Function

[Modified: formatted tabs in code]
Updated 11-Mar-11 10:34am
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

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?
CARisk3 11-Mar-11 16:48pm
I'm quite familiar with him. I've been on this board for about 2-3 years as what everyone would probably call a lurker. I take things in and only respond when I absolutely feel the need to. I get a lot of amusement and information from this board and enjoy the camaraderie between everyone.

When I'm really stuck and can't find an answer here or on google then I post a question.
William Winner 11-Mar-11 16:52pm
Um...ok. Thanks?
milenalukic 11-Mar-11 17:19pm
When I initially joined I was googling for info. After some time I noticed that codeproject comes up often and with good solutions so I began to frequent the site more. Only recently did I have the courage to post my first question and then while waiting for a reply I had a look at unanswered questions and found that I could help a few people out. Since then I enjoy posting questions and looking through the unanswered. Yesterday Dalek posted a comment to my question and I checked out his profile. I might become addicted to this!!
CARisk3 11-Mar-11 17:25pm
I'm already addicted. I'm on here almost every day Monday - Friday. And I usually spend about 1/2 an hour reading through the lounge post. I'm was thinking about writing up my solution for a very compact way to pass information between listboxes. I have 4 - 6 listboxes on one page and used two routines to handle on the moving of selected items back and forth. I thought it was very sleek and compact. But I'm coming from 2002/2003 into 2010 so maybe what I did was pretty standard for 2010.

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.

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

        dv = dsAddPermission.Select(DataSourceSelectArguments.Empty)

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

        Return bCheck

    End Function
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