Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > Visual Web Developer 2008
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Web Developer 2008 Discuss creating ASP.NET 3.5 sites with Microsoft's Visual Web Developer 2008. If your question is more specific to a piece of code than the Visual tool, see the ASP.NET 3.5 forums instead. If your question is specific to the "Express Edition" be sure to state that in your post.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2008 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #21 (permalink)  
Old January 31st, 2009, 04:18 PM
Authorized User
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
Thumbs up Awesome!

Thanks Lee. I had some structural issues on the query, but I moved some things around and its working great! Thanks so much for all your help!

  #22 (permalink)  
Old February 1st, 2009, 12:17 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts

You're welcome.

If you like, feel free to click the Thanks button on any posts you found helpful.
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

if (this.PostHelpedYou)
The Following User Says Thank You to Lee Dumond For This Useful Post:
mashype (February 1st, 2009)
  #23 (permalink)  
Old May 19th, 2010, 03:49 AM
Registered User
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default access data source

Originally Posted by Lee Dumond View Post
This is getting somewhat confusing, as there are two different users asking stuff in this same thread.

Okay, this is for Mashype. Based on the code example you did posted yesterday. I am using a DetailsView here. Here is the entire code sample.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <form id="form1" runat="server">
         <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="UserID"
            DataSourceID="SqlDataSource1" Height="50px" Width="125px">
               <asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False" ReadOnly="True"
                  SortExpression="UserID" />
               <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
               <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProdConnectionString %>"
            SelectCommand="SELECT [UserID], [UserName], [LastName] FROM [TblUsers] WHERE ([UserName] = @UserName)"
               <asp:Parameter Name="UserName" Type="String" />

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
   protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
      e.Command.Parameters["@UserName"].Value = Context.User.Identity.Name;

This might be a little bit too late but..
I have excactly the same problem but I am using a access data source. I am a beginner and I can't find a solution. How would the code look? Please help me.
  #24 (permalink)  
Old May 19th, 2010, 01:44 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi larsenal,

It's almost the same with an AccessDataSource, except that you don't refer to the parameters by name, but by their index. Here's q quick example using a GridView:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
    DataFile="~/App_Data/Database1.mdb" OnSelecting="AccessDataSource1_Selecting" 
    SelectCommand="SELECT * FROM [Test] WHERE ([UserName] = ?)">
    <asp:Parameter Name="UserName" Type="String" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" 
       DataKeyNames="ID" DataSourceID="AccessDataSource1" />
And then in the Code Behind you need this:

protected void AccessDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
  e.Command.Parameters[0].Value = Context.User.Identity.Name;
This assigns the user name to the first (and only) parameter defined in the query.

Hope this helps,

Imar Spaanjaars
Follow me on Twitter.

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB, and ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Kitty Litter by Placebo (From the album: Battle for the Sun) What's This?

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying data that is related to the login user saif44 ASP.NET 2.0 Basics 0 March 9th, 2006 12:21 PM
Displaying SQLServer data to user sss22 ASP.NET 1.0 and 1.1 Basics 1 October 28th, 2005 01:05 PM
Displaying sessions logged into Win2K Server sachin1979 BOOK: Beginning ASP 3.0 0 September 5th, 2004 08:04 PM
Filter Based Upon Logged In User LandOfToz BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 31st, 2004 12:24 PM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM

All times are GMT -4. The time now is 04:08 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.