Question

Trying to pass a variable in a select statement

Asked by: lvjan777

How can I grab the user name to display only his information in the grid view. I'm using User Authentication and want to match the CurrentUser to the Project Lead Name.

In the following code in the WHERE clause if I put "FirstName LastName" it will work, but I want to grab the person who's logged in and display if Display Name and Current User Name match.
WHERE     (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = "FirstName LastName")

SELECT     ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date, 
                      [Current Status] AS Current_Status, Active, Shop
FROM         projectDetails
WHERE     (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = CurrentUser.DisplayName)
ORDER BY [End Date] DESC
 
 
reference in code behind
Dim X As String
  X = CurrentUser.DisplayName
  displayName.Text = CurrentUser.DisplayName
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-09-10 at 10:32:32ID23720168
Tags

VB.Net

,

IE

,

NA

Topics

.NET

,

Microsoft Visual Basic.Net

,

Scripting Languages

Participating Experts
1
Points
125
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. MySQLFront: Combine FirstName + LastName
    Hello, MySQLFront, Server: Linux Apache, System: WINXP I've searched the forum for similar questions, and there all pretty damn close to getting me finalized, but no cigar. What I am looking to do is combine two fields in the same table to populate another field in the sam...
  2. Need to Change Lastname, Firstname in Outlook
    We are using CRM 3.0 with update rollup 1 on Windows 2003 SP1 Standard, SQL 2000, SP4 on W2K SP4 and Exchange 2003 SP2 on Windows 2003 Enterprise SP1. Currently when someone sends an e-mail from CRM it shows up as Lastname, Firstname in Outlook. I would like this to match our...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mwvisa1Posted on 2008-09-10 at 12:10:30ID: 22441816

SELECT     ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date,
                      [Current Status] AS Current_Status, Active, Shop
FROM         projectDetails
WHERE     (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = @CurrentUser)
ORDER BY [End Date] DESC

Use a parameter @paramname in your SQL text of command and the use command.AddParameter function to set parameter value to CurrentUser.DisplayName.

 

by: lvjan777Posted on 2008-09-10 at 12:22:28ID: 22441934

Here are my parameters: Nothing displays and it doesn't error out. must be very close, just not working.

 <SelectParameters>
                <asp:Parameter DefaultValue="Yes" Name="Active" Type="String" />
                <asp:Parameter DefaultValue="No" Name="Completed" Type="String" />
                <asp:SessionParameter Name="Project_Lead_Name" SessionField="CurrentUser.DisplayName" Type="String" />
            </SelectParameters>

 

by: lvjan777Posted on 2008-09-10 at 12:32:35ID: 22442056

Also tried this:
<asp:Parameter DefaultValue="CurrentUser.DisplayName" Name="Project_Lead_Name" Type="String" />

 

by: mwvisa1Posted on 2008-09-10 at 12:40:58ID: 22442140

If you use this method,

<asp:Parameter DefaultValue="CurrentUser.DisplayName" Name="Project_Lead_Name" Type="String" />

You probably want to set this through code as this is going to take string literal "CurrentUser.DisplayName".  You are wanting to set parameter.Value = CurrentUser.DisplayName.

Is that LINQ syntax?  I mostly use my own data layer, so just want to make sure if you are using LINQ that I am giving proper instruction.

 

by: lvjan777Posted on 2008-09-10 at 12:49:04ID: 22442229

I'm not doing this in code behind

 

by: lvjan777Posted on 2008-09-10 at 12:56:59ID: 22442322

Not sure what LINQ syntax is, using VisualStudio and building with the Grid Views. Here's the page:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Home" title="Dashboard" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div align="left">
        <asp:Panel ID="pnlCurrentProjects" runat="server" HorizontalAlign="Left" Width="100%">
            <br />
            <asp:Label ID="lblDashboard" runat="server" CssClass="big" ForeColor="#56A8E2" Text="Dashboard"></asp:Label><br />
            <br />
            <br />
            <table border="0" bgcolor="#eeeeee" cellpadding="10">
                <tr>
                    <td colspan="3" rowspan="3" style="height: 105px" class="dashedTable" valign="top">
                        <table>
                            <tr>
                                <td class="subHead">
                        Welcome
                                    <asp:Label ID="displayName" runat="server"></asp:Label></td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td class="detailLabel">
                        This is your dashboard. On it you will find your upcoming projects listed below
                                    meeting the criteria of being either the lead or on the team.</td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td class="bold">
                                    You may do the following:</td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td class="detailLabel">
                                    &nbsp;-
                                    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/createProject.aspx">Create a new project</asp:LinkButton><br />
                                    &nbsp;-
                                    <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="~/projectList.aspx">View your full project list</asp:LinkButton><br />
                                    &nbsp;-
                                    <asp:LinkButton ID="LinkButton3" runat="server" PostBackUrl="~/admin.aspx">Add a new user/edit dropdown lists</asp:LinkButton></td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                </tr>
                <tr>
                </tr>
            </table>
            <br />
            <br />
            &nbsp;<asp:SqlDataSource ID="SqlCurrentProjectList" runat="server" ConnectionString="<%$ ConnectionStrings:RANSProjectTrackerConnectionString %>"
                DeleteCommand="DELETE FROM [projectDetails] WHERE [ID] = ?" InsertCommand="INSERT INTO [projectDetails] ([ID], [Project Title], [Project Priority], [Project Lead Name], [End Date], [Current Status], [Active]) VALUES (?, ?, ?, ?, ?, ?, ?)"
                ProviderName="<%$ ConnectionStrings:RANSProjectTrackerConnectionString.ProviderName %>"
                SelectCommand="SELECT ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date, [Current Status] AS Current_Status, Active, Shop FROM projectDetails WHERE (Active = ?) AND (Completed = ?) ORDER BY [End Date] DESC"
                UpdateCommand="UPDATE [projectDetails] SET [Project Title] = ?, [Project Priority] = ?, [Project Lead Name] = ?, [End Date] = ?, [Current Status] = ?, [Active] = ? WHERE [ID] = ?">
                <SelectParameters>
                    <asp:Parameter DefaultValue="Yes" Name="Active" Type="String" />
                    <asp:Parameter DefaultValue="No" Name="Completed" Type="String" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Project_Title" Type="String" />
                    <asp:Parameter Name="Project_Priority" Type="String" />
                    <asp:Parameter Name="Project_Lead_Name" Type="String" />
                    <asp:Parameter Name="End_Date" Type="DateTime" />
                    <asp:Parameter Name="Current_Status" Type="String" />
                    <asp:Parameter Name="Active" Type="String" />
                    <asp:Parameter Name="ID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                    <asp:Parameter Name="Project_Title" Type="String" />
                    <asp:Parameter Name="Project_Priority" Type="String" />
                    <asp:Parameter Name="Project_Lead_Name" Type="String" />
                    <asp:Parameter Name="End_Date" Type="DateTime" />
                    <asp:Parameter Name="Current_Status" Type="String" />
                    <asp:Parameter Name="Active" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Black" Height="25px"
                Text="Current Projects"></asp:Label>&nbsp;
            <asp:GridView ID="gvCurrentProjectList" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                BackColor="White" BorderColor="White" BorderStyle="None" BorderWidth="0px" CellPadding="4"
                DataSourceID="sqlCurrentProjectList" ForeColor="Black" GridLines="Horizontal"
                Width="600px">
                <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                <Columns>
                    <asp:CommandField HeaderText="Compare" ShowSelectButton="True" Visible="False" />
                    <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="projectDetails.aspx?ID={0}"
                        DataTextField="Project_Title" HeaderText="Project Title" />
                    <asp:BoundField DataField="Project_Title" HeaderText="Project Title" SortExpression="Project_Title"
                        Visible="False" />
                    <asp:BoundField DataField="Project_Priority" HeaderText="Priority" SortExpression="Project_Priority" />
                    <asp:BoundField DataField="Project_Lead_Name" HeaderText="Lead" SortExpression="Project_Lead_Name" />
                    <asp:BoundField DataField="Shop" HeaderText="Shop" SortExpression="Shop" />
                    <asp:BoundField DataField="End_Date" DataFormatString="{0:d}" HeaderText="Due Date"
                        HtmlEncode="False" SortExpression="End_Date" />
                    <asp:BoundField DataField="Current_Status" HeaderText="Status" SortExpression="Current_Status" />
                    <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" Visible="False" />
                </Columns>
                <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="LightGray" BorderStyle="None" BorderWidth="0px" CssClass="normal"
                    Font-Strikeout="False" ForeColor="Black" />
                <AlternatingRowStyle BackColor="#EEEEEE" ForeColor="#404040" />
            </asp:GridView>
        </asp:Panel>
        <asp:SqlDataSource ID="SqlTeamListOnly" runat="server" ConnectionString="<%$ ConnectionStrings:RANSProjectTrackerConnectionString %>"
            DeleteCommand="DELETE FROM [projectDetails] WHERE [ID] = ?" InsertCommand="INSERT INTO [projectDetails] ([ID], [Project Title], [Project Priority], [Project Lead Name], [End Date], [Current Status], [Active]) VALUES (?, ?, ?, ?, ?, ?, ?)"
            ProviderName="<%$ ConnectionStrings:RANSProjectTrackerConnectionString.ProviderName %>"
            SelectCommand="SELECT ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date, [Current Status] AS Current_Status, Active, Shop FROM projectDetails WHERE (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = @CurrentUser) ORDER BY [End Date] DESC"
            UpdateCommand="UPDATE [projectDetails] SET [Project Title] = ?, [Project Priority] = ?, [Project Lead Name] = ?, [End Date] = ?, [Current Status] = ?, [Active] = ? WHERE [ID] = ?">
            <SelectParameters>
                <asp:Parameter DefaultValue="Yes" Name="Active" Type="String" />
                <asp:Parameter DefaultValue="No" Name="Completed" Type="String" />
                <asp:SessionParameter Name="Project_Lead_Name" SessionField=@CurrentUser.DisplayName Type="String" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Project_Title" Type="String" />
                <asp:Parameter Name="Project_Priority" Type="String" />
                <asp:Parameter Name="Project_Lead_Name" Type="String" />
                <asp:Parameter Name="End_Date" Type="DateTime" />
                <asp:Parameter Name="Current_Status" Type="String" />
                <asp:Parameter Name="Active" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:Parameter Name="Project_Title" Type="String" />
                <asp:Parameter Name="Project_Priority" Type="String" />
                <asp:Parameter Name="Project_Lead_Name" Type="String" />
                <asp:Parameter Name="End_Date" Type="DateTime" />
                <asp:Parameter Name="Current_Status" Type="String" />
                <asp:Parameter Name="Active" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        &nbsp;
        <br />
            <asp:GridView ID="gvTeamListOnly" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlTeamListOnly" Width="98%" BorderWidth="0px" CellPadding="4" AllowSorting="True">
                <Columns>
                    <asp:CommandField HeaderText="Compare" ShowSelectButton="True" Visible="False" />
                    <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="projectDetails.aspx?ID={0}"
                        DataTextField="Project_Title" HeaderText="Project Title" />
                    <asp:BoundField DataField="Project_Title" HeaderText="Project Title" SortExpression="Project_Title"
                        Visible="False" />
                    <asp:BoundField DataField="Project_Priority" HeaderText="Priority" SortExpression="Project_Priority" />
                    <asp:BoundField DataField="Project_Lead_Name" HeaderText="Lead" SortExpression="Project_Lead_Name" />
                    <asp:BoundField DataField="Shop" SortExpression="Shop" HeaderText="Shop" >
                        <ItemStyle CssClass="detailLabel" HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="End_Date" DataFormatString="{0:d}" HeaderText="Due Date"
                        HtmlEncode="False" SortExpression="End_Date" />
                    <asp:BoundField DataField="Current_Status" HeaderText="Status" SortExpression="Current_Status" />
                    <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" Visible="False" />
                </Columns>
                 <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="LightGray" ForeColor="Black" BorderWidth="0px" CssClass="normal" Font-Strikeout="False" BorderStyle="None" />
                <AlternatingRowStyle BackColor="#EEEEEE" ForeColor="#404040" />
            </asp:GridView>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RANSProjectTrackerConnectionString %>"
            ProviderName="<%$ ConnectionStrings:RANSProjectTrackerConnectionString.ProviderName %>"
            SelectCommand="SELECT [Project Title] AS Project_Title, [Project Lead Name] AS Project_Lead_Name FROM [projectDetails] WHERE ([Project Lead Name] = ?)">
            <SelectParameters>
                <asp:SessionParameter Name="Project_Lead_Name" SessionField="CurrentUser.DisplayName" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
   
    </div>
</asp:Content>

 

by: mwvisa1Posted on 2008-09-10 at 13:03:32ID: 22442391

Ah, sorry, I have been so use to creating my own connections that I didn't recognize the SqlDatasource structure.  

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx

See this.  SessionParameter lets you add from session variables.

See 4guysfromrolla site on examples for using other parameter types.

But this is what I meant.  I wanted you to setup the parameter, giving it a name that you can reference in the code behind and assign value.

http://www.pluralsight.com/community/blogs/fritz/archive/2006/01/16/18054.aspx

 

 

by: lvjan777Posted on 2008-09-10 at 13:38:25ID: 22442733

no luck, I'm just not getting it.  Thank you for helping though, anything else I should try :)

Last Attempt:
 SelectCommand="SELECT ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date, [Current Status] AS Current_Status, Active, Shop FROM projectDetails WHERE (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = ?) ORDER BY [End Date] DESC"

 <SelectParameters>
                <asp:Parameter DefaultValue="Yes" Name="Active" Type="String" />
                <asp:Parameter DefaultValue="No" Name="Completed" Type="String" />
                <asp:QueryStringParameter Type="String" Name="Project_Lead_Name" QueryStringField="  DashboardUser " />
            </SelectParameters>
           
code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim X As String
        X = CurrentUser.DisplayName
        displayName.Text = CurrentUser.DisplayName


        Dim DashboardUser As New SessionParameter()
        DashboardUser.Name = " DashboardUser "
        DashboardUser.Type = TypeCode.String
        DashboardUser.SessionField = " DashboardUser "


    End Sub

 

by: mwvisa1Posted on 2008-09-10 at 13:50:59ID: 22442888

Did you see the last link  They were doing your exact case pretty much.  Only difference they used User.Identity.Name instead of CurrentUser.DisplayName.  Take a look at that link if you have not already.

 

by: lvjan777Posted on 2008-09-10 at 16:28:39ID: 22444128

I'm trying the example from the last link.

What event do I use instead of 'Inserting'. I can't get the page break to fire the event. I've tried, Selecting, Selected.  Also tried Load, but it doesn't give me the e.command.

Latest Try: Code Behind
    Protected Sub SqlTeamListOnly_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlTeamListOnly.Inserting
        e.Command.Parameters("@Project_Lead_Name").Value = CurrentUser.DisplayName
    End Sub

ASPX:
 SelectCommand="SELECT ID, [Project Title] AS Project_Title, [Project Priority] AS Project_Priority, [Project Lead Name] AS Project_Lead_Name, [End Date] AS End_Date, [Current Status] AS Current_Status, Active, Shop FROM projectDetails WHERE (Active = ?) AND (Completed = ?) AND ([Project Lead Name] = @Project_Lead_Name) ORDER BY [End Date] DESC"

 <SelectParameters>
                <asp:Parameter DefaultValue="Yes" Name="Active" Type="String" />
                <asp:Parameter DefaultValue="No" Name="Completed" Type="String" />
                <asp:Parameter Name="Project_Lead_Name" Type="String" />
            </SelectParameters>
           


 

by: mwvisa1Posted on 2008-09-10 at 19:17:47ID: 22445350

Something like this, you would just name method what you want and use the handles on the correct SqlDatasource control ID.  The event args parameter can be used to access the command as demonstrated.

Protected Sub Projects_Selecting(ByVal sender As Object, _
        ByVal e As SqlDataSourceSelectingEventArgs) Handles SqlTeamListOnly.Selecting
 
        e.Command.Parameters("@CurrentUser").Value = User.Identity.Name
 
    End Sub

                                              
1:
2:
3:
4:
5:
6:

Select allOpen in new window

 

by: lvjan777Posted on 2008-09-11 at 08:28:30ID: 22450983

I get this error:
An OleDbParameter with ParameterName '@CurrentUser' is not contained by this OleDbParameterCollection.

Errors when I run this:
    Protected Sub SqlTeamListOnly_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlTeamListOnly.Selecting
        e.Command.Parameters("@CurrentUser").Value = User.Identity.Name
    End Sub
 
I also have a clsBasePage.vb with this:
 
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
 
Public Class BasePage
    Inherits System.Web.UI.Page
 
    Public Structure StructUser
        Public LoginName As String
        Public DisplayName As String
        Public Role As Integer
    End Structure
 
    Private _User As StructUser
 
    Public ReadOnly Property CurrentUser() As StructUser
        Get
            Return Session("CurrentUser")
        End Get
    End Property
    Sub LoadUser()
        Dim WindowsUser As String
        If CurrentUser.LoginName Is Nothing Then
 
            WindowsUser = Page.User.Identity.Name.ToString
            WindowsUser = (WindowsUser.Split(Convert.ToChar("\")))(1)
 
            'Connect the database and get user
            Dim con As OleDbConnection
            Dim cmd As OleDbCommand
            Dim reader As OleDbDataReader
 
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Visual Studio Projects\RANSProjectTracker\Archive\ProjectTracker.mdb""")
            cmd = New OleDbCommand("select [LoginName], [DisplayName], [Role] from [Users] where LoginName='" + WindowsUser + "'", con)
            con.Open()
            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            If reader.Read() Then
 
                _User = New StructUser
                _User.LoginName = WindowsUser
                _User.DisplayName = reader("DisplayName").ToString
                _User.Role = Convert.ToInt32(reader("Role").ToString)
 
                Session("CurrentUser") = _User
 
            End If
        End If
 
    End Sub
 
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            LoadUser()
        End If
    End Sub
End Class
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:

Select allOpen in new window

 

by: mwvisa1Posted on 2008-09-11 at 08:45:38ID: 22451168

Sorry that was just sample code, you need to put in the proper @parameter name that you are using for the project lead.  Try this: "@Project_Lead_Name".

 

by: lvjan777Posted on 2008-09-11 at 12:35:15ID: 22453751

I'm getting the 'IndexOutOfRangeException was unhandled by user code'

same error:
An OleDbParameter with ParameterName '@Project_Lead_Name' is not contained by this OleDbParameterCollection.

 

by: mwvisa1Posted on 2008-09-11 at 12:40:17ID: 22453794

Is SqlTeamListOnly the datasource name of the datasource you are doing the select from?  If not, then change the Handles clause to be the correct datasource ID.  Double check all the names/queries to ensure they are updated to have accurate code for all the things you are trying to do as their may be code from other attempts still in place causing issues.  The parameters should just be plain asp:Parameters with name matching the @param in query without the @ in front.

 

by: lvjan777Posted on 2008-09-11 at 13:15:10ID: 22454222

When I break point the code behind, it is pulling the correct information from the database, however I then get the 'IndexOutOfRangeException was unhandled by user code'

An OleDbParameter with ParameterName '@Project_Lead_Name' is not contained by this OleDbParameterCollection.

does it have something to do with my clsBasePage:
Sub LoadUser()
        Dim WindowsUser As String
        If CurrentUser.LoginName Is Nothing Then

            WindowsUser = Page.User.Identity.Name.ToString
            WindowsUser = (WindowsUser.Split(Convert.ToChar("\")))(1)

            'Connect the database and get user
            Dim con As OleDbConnection
            Dim cmd As OleDbCommand
            Dim reader As OleDbDataReader

            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Visual Studio Projects\RANSProjectTracker\Archive\ProjectTracker.mdb""")
            cmd = New OleDbCommand("select [LoginName], [DisplayName], [Role] from [Users] where LoginName='" + WindowsUser + "'", con)
            con.Open()
            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            If reader.Read() Then

                _User = New StructUser
                _User.LoginName = WindowsUser
                _User.DisplayName = reader("DisplayName").ToString
                _User.Role = Convert.ToInt32(reader("Role").ToString)

                Session("CurrentUser") = _User

            End If

        End If

    End Sub

 

by: mwvisa1Posted on 2008-09-11 at 13:23:25ID: 22454315

Not quite sure since you indicated in debug you are seeing the selected data come back which would be based on this parameter.  Then you get an error on the parameter.  Something doesn't sound right.  But I am not sure what to tell you to fix at this point so will have to take another look.

 

by: lvjan777Posted on 2008-09-11 at 13:29:24ID: 22454380

GOT IT!!!!

In my select statement I need to make sure the Project_Lead_Name in the select statement and in the asp:paramenter both had the "@Project_Lead_Name'

Thanks for your help, I was soo close a few comments ago!

 

by: lvjan777Posted on 2008-09-11 at 13:31:34ID: 31495182

Thanks, I'm learning and mwvisa1 was right on with his examples and sugestions.

 

by: mwvisa1Posted on 2008-09-11 at 13:34:49ID: 22454447

Yes.  Sorry I didn't catch that.  Figured it was something like that.

Glad you found it.

Regards.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...