Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > Visual Web Developer 2008
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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!

 
Old February 1st, 2009, 12:17 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
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(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
mashype (February 1st, 2009)
 
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.
 
Old May 19th, 2010, 01:44 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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?





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





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