Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 September 27th, 2007, 11:13 AM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parameters

Hi,
I have a problem. I need to save in a parameter @Username the username of someone who inserts data in my create user form. I am using the CREATE USER WIZARD control and for example if I store the Usernme in a variable it's ok:

string var = CreateUserWizard1.UserName;
-----------------------------------------------
but if I want to store it in a parameter like this:

SqlParameter @Username = new SqlParameter();
@Username = CreateUserWizard1.UserName;

I get this: Cannot implicitly convert type 'string' to 'System.Data.SqlClient.SqlParameter'

What's going on plz help!
 
Old September 27th, 2007, 01:05 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm surprised you can create a variable name beginning with an @ at all. The SqlParameter you create is an object with various properties. You need to set those properties, either in the constructor or after creation. One way would be to use:
Code:
SqlParameter userParam = new SqlParameter("@UserName", CreateUserWizard1.UserName);
or
Code:
SqlParameter userParam = new SqlParameter("@UserName", SqlDbType.String);
userParam.Value = CreateUserWizard1.UserName;
There are other ways as described here: http://msdn2.microsoft.com/en-us/lib...parameter.aspx

--

Joe (Microsoft MVP - XML)
 
Old September 27th, 2007, 01:40 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Learnt something from your post :)
The @ symbol can be used as the initial character of an identifier. Its purpose is usually to let you use what is otherwise a keyword be a variable name. More info here: http://msdn2.microsoft.com/en-us/library/aa664670(VS.71).aspx

Not recommended practice though.

--

Joe (Microsoft MVP - XML)
 
Old September 27th, 2007, 03:57 PM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for your help but I need to return the value that is stored in @UserName parameter and when I try, it returns me the name of the parameter not its value
PD: I am using:
SqlParameter userParam = new SqlParameter("@UserName", CreateUserWizard1.UserName);
        Response.Write(userParam);
Whats wrong with that?
 
Old September 27th, 2007, 04:02 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Do, Response.Write(userParam.Value); that should give you the value.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
 
Old September 27th, 2007, 04:04 PM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did it, no problem!
Thanks a lot!
 
Old September 27th, 2007, 05:26 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad it worked out for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
parameters dpkbahuguna ASP.NET 1.x and 2.0 Application Design 0 April 3rd, 2007 07:27 AM
Parameters Dharam80 Access 3 August 19th, 2005 01:59 PM
Parameters coolerbob VB.NET 0 March 9th, 2004 12:48 PM





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