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 March 7th, 2007, 01:34 PM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Binding UserID to new record in Database

Hi all,

I'm sure this is fairly simple so please be gentle.
I'm trying to Bind the logged on user id to a new record within a database.

I have got various different controls (text, listbox etc) successfully passing through the Insert Parameters, but I can't seem to Bind the username.
I have called the username through the script below and can see it displayed in the form but how do I set the insert parameter to equal that?

<script runat="server">

MembershipUser currentUser;

public void Page_Load()
{
currentUser = Membership.GetUser();

}

</script>

Thanks for any help
 
Old March 8th, 2007, 11:57 AM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess im a little confused at what your trying to do, as the 'connecting' happens on your insert.

basically, I do everything with parameters.
So for me:
dim myUser as string = embership.getuser()
dim SQLparams as new specialized.namevaluecollection
SQLparams.add("@userId",myUser)
SQLparams.add("@age, 30)

To execute the code, I cycle through the params and add them as sql parameters.
        For x As Integer = 0 To SQLparams.Keys.Count - 1
            Dim userParameter As New SqlClient.SqlParameter
            userParameter.ParameterName = SQLparams.Keys(x).ToString
            userParameter.Value = SQLparams.Item(x).ToString
            command.Parameters.Add(userParameter)
        Next
        command.ExecuteNonQuery()

ALWAYS use parameters if any of the data is coming from the page to prevent SQL injection attacks.




 
Old March 8th, 2007, 01:01 PM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply - I haven't tried it yet as I think I found the answer in topic: http://p2p.wrox.cpm/topic.asp?TOPIC_ID=40908

using

protected void ActivityEntry_Inserting(object sender, ActivityEntryInsertingEventArgs e)

{e.InputParameters["@UserName"].value = Membership.GetUser().UserName;}

and having

<asp:parameter Type="String" Name="userName" />

in the InsertParameters

My problem now is that I get a compilation error: "The type or namespace name 'ActivityEntryInsertingEventArgs' could not be found (are you missing a using directive or an assembly reference?)"

Where and how do I put the directive / assembly reference?

Sorry I'm new to a lot of this...

Lee



 
Old March 1st, 2010, 07:18 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

instead of using all that try using

user.identity.name when inserting parameters.





Similar Threads
Thread Thread Starter Forum Replies Last Post
TreeView Binding With DataBase sumith ASP.NET 2.0 Basics 2 September 16th, 2009 06:12 AM
Loading SQLserver database with ASPNET userID cJeffreywang ASP.NET 1.0 and 1.1 Professional 0 March 28th, 2007 07:25 PM
How to binding picture file in database ? mojo VB.NET 1 September 7th, 2005 06:49 PM
RDS Single Record and Table Binding with Access qwerty Classic ASP Databases 0 July 15th, 2003 02:20 PM





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