Solved

CreateUserWizard - Custom Wizard Step Input into Stored Proc - How to Bind New TxtBoxes (C#)

Posted on 2008-10-27
4
1,156 Views
Last Modified: 2013-12-17
Hi,

I am using the asp 2.0 Website Administration Tool to control user administration and I am using the createuserwizard to add new members into my site.  I want to have a custom wizard step that allows me to input user detail information (First Name, Last Name, Company, Phone Number).  I have a SQL 2005 table that this information should be entered into and an input stored proc to do the work.

 Where I am stuck: I have seen a bunch of examples ( including http://aspnet.4guysfromrolla.com/articles/070506-1.aspx) that do everything in the source code, including some inline sql.  I cannot do this.  I need to handle everything that can be through the wizard tool itself and/or C# code behind.  I have the step created, which includes the four labes and text boxes as well as the object data source, but I do not know how to bind the txt boxes to the data source.  I am new and having a hard time doing this without an example.

 Can anyone help?

Thanks,

0
Comment
Question by:AJ0424
  • 3
4 Comments
 
LVL 7

Assisted Solution

by:keustermans
keustermans earned 250 total points
ID: 22820724
Below is a function that you can use to use a stored proc to send data to the database

function parameters are as follows

sql -  is a inline sql statement or a stored procedure name

commandtype - Sysytem.Data.CommandType.StoredProcedure for a stored procedure or Sysytem.Data.CommandType.Text for inline sql

Parameters is a Collection of SqlParameters

This function is part of a class that I have writtens so connectionString is iniialized when I create an instance of the class and you will have to replace the factory calls with your own code.

This should be enough to get you going
      public int ExecuteNonQuery(string sql, CommandType commandType, 

                                   IDataParameterCollection parameters)

        {

            bool externalConnection = false;

            IDbConnection connection = null;

            try

            {

                

                connection = factory.CreateConnection();

                connection.ConnectionString = connectionString;

                

                IDbCommand command = factory.CreateCommand();

                command.CommandType = commandType;

                command.CommandText = sql;
 

                if (parameters != null)

                {

                    foreach (IDataParameter param in parameters)

                    {

                        command.Parameters.Add(param);

                    }

                }

                command.Connection = connection;

                if (connection.State == ConnectionState.Closed)

                {

                    connection.Open();

                }
 

                return command.ExecuteNonQuery();

            }

            catch (Exception ex)

            {
 

                throw new Exception(ex.Message.ToString());
 

            }

            finally

            {

                if (connection.State == ConnectionState.Open)

                {

                    connection.Close();

                    connection.Dispose();

                }

            }

        }

Open in new window

0
 

Author Comment

by:AJ0424
ID: 22825181
Thank you keustermans.  I will look at this tonight and see if I can make it work.

AJ
0
 

Author Comment

by:AJ0424
ID: 22832643
Hi...the problem I am having isn't connecting to the database, it is getting the user input out of the textboxes in this wizard.  I need to collect the entered data - example:

John
Smith
ABC Company
333-555-1212

and then send that info back as the parameters for my stored proc.  I just don't know how to pull it out of the createuser wizard.

Thanks,
AJ
0
 

Accepted Solution

by:
AJ0424 earned 0 total points
ID: 22878503
I was using the wrong step.  Once I corrected, the code worked fine.
        protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)

        {
 

            string firstName = GetUserData("txtFName");

            string lastName = GetUserData("txtLName");

            string company = GetUserData("txtCompany");

            string phone = GetUserData("txtPhone");
 

            TextBox UserName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");

            string username = UserName.Text;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now