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
Register
Register | FAQ | Members List | Calendar | 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
Reply
 
Thread Tools Display Modes
  #21 (permalink)  
Old January 31st, 2009, 03: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!

Reply With Quote
  #22 (permalink)  
Old January 31st, 2009, 11:17 PM
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
Default

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

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
Reply With Quote
The Following User Says Thank You to Lee Dumond For This Useful Post:
mashype (January 31st, 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

Quote:
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:

Code:
<%@ 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">
   <title></title>
</head>
<body>
   <form id="form1" runat="server">
      <div>
         <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="UserID"
            DataSourceID="SqlDataSource1" Height="50px" Width="125px">
            <Fields>
               <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" />
            </Fields>
         </asp:DetailsView>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProdConnectionString %>"
            SelectCommand="SELECT [UserID], [UserName], [LastName] FROM [TblUsers] WHERE ([UserName] = @UserName)"
            OnSelecting="SqlDataSource1_Selecting">
            <SelectParameters>
               <asp:Parameter Name="UserName" Type="String" />
            </SelectParameters>
         </asp:SqlDataSource>
      </div>
   </form>
</body>
</html>
Code-behind:

Code:
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.
Reply With Quote
  #24 (permalink)  
Old May 19th, 2010, 01:44 PM
Imar's Avatar
Wrox Author
Points: 66,975, Level: 100
Points: 66,975, Level: 100 Points: 66,975, Level: 100 Points: 66,975, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,177
Thanks: 65
Thanked 1,401 Times in 1,381 Posts
Default

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:

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

Code:
 
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
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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?
Reply With Quote
Reply


Thread Tools
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 11:21 AM
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 03:48 AM



All times are GMT -4. The time now is 07:29 PM.


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