Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 July 24th, 2006, 02:37 PM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting user_ID of logged in user


I am sure this is a very easy question, but I just can't work it out.

The logged in user is going to create a job using the insert mode of a formview control. I need the user_id (foriegn key) field in the job table to automatically populate with the user_id of the logged in user. I can't get this to work, any ideas?

 
Old July 25th, 2006, 05:40 AM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my searching for how to do this, I have found that ms doesn't want you to use the user_id, they want you to use the loginName. In any case, I just need to add the loginName of the current user to a table when an insert is performed, here is what I have currently.

In the codebehind

   protected void FormView1_ItemInserting(Object sender, System.Web.UI.WebControls.FormViewInsertEventArgs e)
   {
        e.Values["CustLogin"] = User.Identity.Name;
   }

but this isn't working.
I don't know if there is a better way to do this, perhaps without using the codebehind, but any help would be appreciated.


 
Old July 28th, 2006, 12:16 PM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bluewavestrider
Default

During either The formview's ItemInserting or ItemInserted event, do the following:
1. Create a class in the App_Code folder that would do your database operation. The class can receive the User.Identity.Name or whatever you want to store as a parameter.
2. Use this parameter in your Sql statement. e.g "INSERT INTO User (loginName) VALUES('" + nameParameter + "');";
That's just about it, or at least that's how I do my simultaneous data operations on databases.


Live in fragments no longer. Only connect.
 
Old July 28th, 2006, 12:48 PM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default


That worked, thanks.







Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I check whether a user is logged in or out rittwick PHP Databases 1 August 19th, 2007 04:47 PM
to keep the user logged in until he sign out sarah lee ASP.NET 1.0 and 1.1 Basics 14 December 14th, 2006 11:55 AM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
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.