Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 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
  #1 (permalink)  
Old July 24th, 2006, 02:37 PM
Authorized User
Join Date: May 2006
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old July 25th, 2006, 05:40 AM
Authorized User
Join Date: May 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

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.

Reply With Quote
  #3 (permalink)  
Old July 28th, 2006, 12:16 PM
Registered User
Join Date: Jul 2006
Location: Accra, , Ghana.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bluewavestrider

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.
Reply With Quote
  #4 (permalink)  
Old July 28th, 2006, 12:48 PM
Authorized User
Join Date: May 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

That worked, thanks.

Reply With Quote

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

All times are GMT -4. The time now is 02:09 PM.

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