Form which accepts & validate user input and saves that input to SQL Server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parshupooja
    New Member
    • Jun 2007
    • 159

    Form which accepts & validate user input and saves that input to SQL Server

    Hi,

    I am working in Asp.Net 2.0, SQL Server, C#.
    I am trying to create a User Input form which has lots of fields such as :
    salutation;
    Firstname:
    lastname:
    address:
    Zip:
    Phone:
    Industry:
    and many more. i want to validate user input and than it should save into sql server 2005 and additionally if am being able to send email also that will be great. could you please lead me toward a article or tutorial which can guide me through this process. This is gonna be first time that I am creating a huge form, before this i have created a small forms by using sqldatasource and formview of asp.net 2.0. any help will be appreciated.

    Thank You
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by parshupooja
    Hi,

    I am working in Asp.Net 2.0, SQL Server, C#.
    I am trying to create a User Input form which has lots of fields such as :
    salutation;
    Firstname:
    lastname:
    address:
    Zip:
    Phone:
    Industry:
    and many more. i want to validate user input and than it should save into sql server 2005 and additionally if am being able to send email also that will be great. could you please lead me toward a article or tutorial which can guide me through this process. This is gonna be first time that I am creating a huge form, before this i have created a small forms by using sqldatasource and formview of asp.net 2.0. any help will be appreciated.

    Thank You
    You could search Google or another search engine for C# validate user input and you should get some examples. Just think about designing your page in pieces. Start with basic information like first name and last name then test your validation. To insert the data into a database you will need some insert stored procedures. Your stored procedure will most likely have a parameter for every field on the page.

    Good Luck

    Nathan

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      Originally posted by parshupooja
      Hi,

      I am working in Asp.Net 2.0, SQL Server, C#.
      I am trying to create a User Input form which has lots of fields such as :
      salutation;
      Firstname:
      lastname:
      address:
      Zip:
      Phone:
      Industry:
      and many more. i want to validate user input and than it should save into sql server 2005 and additionally if am being able to send email also that will be great. could you please lead me toward a article or tutorial which can guide me through this process. This is gonna be first time that I am creating a huge form, before this i have created a small forms by using sqldatasource and formview of asp.net 2.0. any help will be appreciated.

      Thank You
      I will be happy to walk you through the process if you like. First step should be to create the HTML (or at least a working portion of it).

      You will need <asp:Label>'s and <asp:TextBox> 's for the fields. I would use a standard naming convention, so for instance the label for the first name would be something like lblFirstName and its corresponding TextBox would be txtFirstName.

      Once that is done, you will need validators to make sure the input is valid. Everything but the Phone and Zip will just use have the RequiredFieldVa lidators. For the Phone and Zip textbox's, use RegularExpressi onValidators. There are a few prebuilt expressions in VS 2005, and luckily there are ones for US Phone and US Zip Code. Use those with the corresponding Textboxes.

      When you are done with all this, I will help you with the next step.


      EDIT:

      If you want links to sites, here are some:


      Information about INSERT statements for SQL

      Information about sending email through ASP .NET
      Last edited by TRScheel; Jun 14 '07, 03:15 PM. Reason: Added links

      Comment

      • parshupooja
        New Member
        • Jun 2007
        • 159

        #4
        Thank You TRScheel. as soon as finish this i'll back to seek help.
        Last edited by parshupooja; Jun 14 '07, 03:35 PM. Reason: spelling mistake

        Comment

        • parshupooja
          New Member
          • Jun 2007
          • 159

          #5
          Hi, Here are fields which I have created. Reason behind pasting this is to show you that how it looks so far? Please guide me for the next step and feel free to suggest in following html
          Code:
          <%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="test_Default3" Title="Untitled Page" %>
           
          <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
          <div>
          <h3>
          </h3>
          <asp:ValidationSummary ID="valSum" runat="server" HeaderText="You must enter a valid value in the following fields:"
          DisplayMode="SingleParagraph" Font-Names="verdana" Font-Size="12" />
          <br />
          <br />
          <!-- sign-in -->
          <table border="0" width="600">
          <tr>
          <td colspan="3">
          &nbsp;</td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>First Name*:</b>
          </td>
          <td>
          <asp:TextBox ID="fn" MaxLength="20" Width="200px" runat="server" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="fn" ErrorMessage="first name"
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Last Name*:</b>
          </td>
          <td>
          <asp:TextBox ID="ln" MaxLength="40" Width="200px" runat="server" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="ln" ErrorMessage="last name"
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Title</b>
          </td>
          <td>
          <asp:TextBox ID="TextBox1" Width="200px" runat="server" />
          </td>
          <td>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Email Address*:</b>
          </td>
          <td>
          <asp:TextBox ID="email" Width="200px" MaxLength="60" runat="server" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="emailReqVal" ControlToValidate="email" ErrorMessage="Email. "
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator ID="emailRegexVal" ControlToValidate="email" ErrorMessage="Email. "
          Display="Static" ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
          Font-Names="Arial" Font-Size="11" runat="server">
          Not a valid e-mail address. Must follow [email="email@host.doma"]email@host.doma[/email]in.
          </asp:RegularExpressionValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Phone*:</b>
          </td>
          <td>
          <asp:TextBox ID="phone" MaxLength="20" runat="server" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="phoneReqVal" ControlToValidate="phone" ErrorMessage="Phone. "
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator ID="phoneRegexVal" ControlToValidate="phone" ErrorMessage="Phone. "
          ValidationExpression="(^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)"
          Display="Static" Font-Names="Arial" Font-Size="11" runat="server">
          Must be in form: (XXX) XXX-XXXX
          </asp:RegularExpressionValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Company*:</b>
          </td>
          <td>
          <asp:TextBox ID="company" MaxLength="40" Width="200px" runat="server" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="company" ErrorMessage="last name"
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Address:</b>
          </td>
          <td>
          <asp:TextBox ID="address" Width="200px" runat="server" TextMode="MultiLine" />
          </td>
          <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="address" ErrorMessage="address"
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>City:</b>
          </td>
          <td>
          <asp:TextBox ID="city" Width="200px" runat="server" MaxLength="20"/>
          </td>
          <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="city" ErrorMessage="city"
          Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>State:</b>
          </td>
          <td>
          <asp:TextBox ID="state" Width="30px" MaxLength="2" runat="server" />&nbsp;
           
          <b>Zip Code:</b>&nbsp;
          <asp:TextBox ID="zip" Width="60px" MaxLength="5" runat="server" />
          </td>
          <td>
          <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="zip"
          ErrorMessage="Zip Code. " ValidationExpression="^\d{5}$" Display="Static" Font-Names="Arial"
          Font-Size="11" runat="server">
          Zip code must be 5 numeric digits
          </asp:RegularExpressionValidator>
          </td>
          </tr>
          <tr>
          <td align="right" style="width: 171px">
          <b>Country:</b>
          </td>
          <td>
          <asp:DropDownList ID="country" runat="server">
          <asp:ListItem></asp:ListItem>
           
           
          <asp:ListItem>Argentina</asp:ListItem>
          <asp:ListItem>Australia </asp:ListItem>
          <asp:ListItem>Austria </asp:ListItem>
          <asp:ListItem>Bahamas </asp:ListItem>
          <asp:ListItem>Belgium </asp:ListItem>
          <asp:ListItem>Brazil </asp:ListItem>
          <asp:ListItem>Bolivia</asp:ListItem> 
          <asp:ListItem>Canada </asp:ListItem>
          <asp:ListItem>Chile</asp:ListItem>
          <asp:ListItem>China</asp:ListItem>
          <asp:ListItem>Colombia</asp:ListItem>
          <asp:ListItem>Costa Rica </asp:ListItem>
          <asp:ListItem>Croatia </asp:ListItem>
          <asp:ListItem>Cuba </asp:ListItem>
          <asp:ListItem>Denmark</asp:ListItem>
          <asp:ListItem>Ecuador</asp:ListItem>
          <asp:ListItem>Egypt</asp:ListItem>
          <asp:ListItem>El Salvador </asp:ListItem>
          <asp:ListItem>Finland </asp:ListItem>
          <asp:ListItem>France </asp:ListItem>
          <asp:ListItem>Germany </asp:ListItem>
          <asp:ListItem>Greece </asp:ListItem>
          <asp:ListItem>Guatemala </asp:ListItem>
          <asp:ListItem>Honduras </asp:ListItem>
          <asp:ListItem>Honk Kong</asp:ListItem>
          <asp:ListItem>Iceland </asp:ListItem>
          <asp:ListItem>India </asp:ListItem>
          <asp:ListItem>Ireland </asp:ListItem>
          <asp:ListItem>Israel </asp:ListItem>
          <asp:ListItem>Italy </asp:ListItem>
          <asp:ListItem>Jamaica </asp:ListItem>
          <asp:ListItem>Japan </asp:ListItem>
          <asp:ListItem>Luxembourg </asp:ListItem>
          <asp:ListItem>Mexico </asp:ListItem>
          <asp:ListItem>Morocco </asp:ListItem>
          <asp:ListItem>Netherlands </asp:ListItem>
          <asp:ListItem>New Zealand </asp:ListItem>
          <asp:ListItem>Nigeria </asp:ListItem>
          <asp:ListItem>Norway </asp:ListItem>
          <asp:ListItem>Paraguay </asp:ListItem>
          <asp:ListItem>Peru </asp:ListItem>
          <asp:ListItem>Poland </asp:ListItem>
          <asp:ListItem>Portugal </asp:ListItem>
          <asp:ListItem>Russia </asp:ListItem>
          <asp:ListItem>Saudi Arabia </asp:ListItem>
          <asp:ListItem>South Africa</asp:ListItem>
          <asp:ListItem>Spain </asp:ListItem>
          <asp:ListItem>Sweden </asp:ListItem>
          <asp:ListItem>Switzerland </asp:ListItem>
          <asp:ListItem>Taiwan </asp:ListItem>
          <asp:ListItem>Turkey</asp:ListItem>
          <asp:ListItem>United Kingdom </asp:ListItem>
          <asp:ListItem>United States </asp:ListItem>
          <asp:ListItem>Uruguay </asp:ListItem>
          <asp:ListItem>Venezuela </asp:ListItem>
          <asp:ListItem>Other </asp:ListItem>
          </asp:DropDownList>
          </td>
          <td>
          <asp:RequiredFieldValidator ID="countryReqVal" ControlToValidate="country" ErrorMessage="Country. "
          Display="Static" InitialValue="" Font-Names="Verdana" Font-Size="12" runat="server">
          *
          </asp:RequiredFieldValidator>
          </td>
          </tr>
          <tr>
          <td colspan="3">
          &nbsp;</td>
          </tr>
          <tr>
          <td colspan="3">
          </td>
          </tr>
          <tr>
          <td align="right">
          <b >I am interested in:</b>
          </td>
          <td>
          <asp:CheckBoxList ID="interest" runat="server" Width="208px" RepeatDirection="Horizontal">
          <asp:ListItem>Training</asp:ListItem>
          <asp:ListItem>Activity</asp:ListItem>
          <asp:ListItem>Learning</asp:ListItem>
          </asp:CheckBoxList>
          </td>
          <td>
           
           
          </td>
          </tr>
          <tr>
          <td align="right">
          <b>How did you hear about us</b>
          </td><td>
          <asp:RadioButtonList ID="source" runat="server">
          <asp:ListItem>Email</asp:ListItem>
          <asp:ListItem>Direct Mail</asp:ListItem>
          <asp:ListItem>Referral</asp:ListItem>
          <asp:ListItem>Publication</asp:ListItem>
          <asp:ListItem>Tradeshow</asp:ListItem>
          <asp:ListItem>Website Link</asp:ListItem>
          <asp:ListItem>Internet</asp:ListItem>
          </asp:RadioButtonList>
          <b>Other</b>
          <asp:TextBox ID="other" runat="server" />
          </td>
          </tr>
          </table>
          <br />
          <br />
          <input id="Submit1" runat="server" type="submit" value="Sign In" />
          </div>
          </asp:Content>

          Comment

          • TRScheel
            Recognized Expert Contributor
            • Apr 2007
            • 638

            #6
            Nicely done, I just tested your site, and it looks functional.

            A few notes on the HTML:
            • Use clarifiers for your IDs (ex, textbox id's are always prefixed with txt, dropdownlists with ddl, checkboxes with chk, etc)
            • Instead of <b> </b> use labels (and dont forget the above point when naming them) with css styling
            • I normally have validators have their initials as their definer, and then carry the same suffix as the object they are validating (ex, if the regular expression validator was validating txtPhone, then the validator would be named revPhone)


            Those are all styling points, up to you whether you want to put them into your code.

            This SHOULD be done though:
            Go back through all your input fields and put a maximum character amount. This is so when you create your sql table, you know the maximum size you will be passing to it. Its not needed, as you can use variable sized inputs, but it will help.


            Onto the code. Now that you have what can be referenced as pseudo code, create a User class that has all these properties. Here are a few pointers with that class:
            • Private variables, public properties (stylistic, but it also lets you change the implementation later without breaking code everywhere)
            • Include two enums for the interested in and where did you hear about us ( sample code included at the end of this post )
            • Include a function to return SqlParamter[] and call it something like GetSqlParameter s. For now just have it return null. We will fill in that function later when we pass this information to your sql statement.
            • Everything but the zip code will probably be a string and the zip code will probably be an int, although you can have that be a string as well.
            • Make sure to include a variable (string) for Other in case they select that option



            Now the enum code. You have two distinct opportunities for the enums. One that only allows one value, another that the user can select multiple options. If you want to have one enum that can have multiple options, make each value in the enum a iterator of 2 ^ x (1, 2, 4, 8, 16, 32, 64, 128, etc). Examples of the enums are as such:

            [code=cpp]
            public enum InterestedIn
            {
            Training = 1,
            Activity = 2,
            Learning = 4
            }

            public enum ReferredFrom
            {
            Email,
            DirectMail,
            Referral,
            Publication,
            Tradeshow,
            WebsiteLink,
            Internet
            }
            [/code]

            Comment

            • parshupooja
              New Member
              • Jun 2007
              • 159

              #7
              hi,

              thank you for your feedback and help. From the HTML point of view I understood everything but didn't understand anything regards to next step. I guess its little higher level for me. Could you please explain in more detail. By User class do you mean adding new class to existing project? Are you trying to lead me to multi-tier architecture? I am kind of confused.

              Thank You.

              Comment

              • TRScheel
                Recognized Expert Contributor
                • Apr 2007
                • 638

                #8
                Originally posted by parshupooja
                hi,

                thank you for your feedback and help. From the HTML point of view I understood everything but didn't understand anything regards to next step. I guess its little higher level for me. Could you please explain in more detail. By User class do you mean adding new class to existing project? Are you trying to lead me to multi-tier architecture? I am kind of confused.

                Thank You.
                If this is done in Visual Studio, right click your solution and add file (like you would a web page). Select the class object. Name it something like User, and it should auto fill everything.

                I may ask you if you want to create an App_Data folder, do so if it does. If it doesnt, no worries.

                It should auto create a file that looks similiar to:

                [code=cpp]
                using System;
                using System.Data;
                using System.Configur ation;
                using System.Web;
                using System.Web.Secu rity;
                using System.Web.UI;
                using System.Web.UI.W ebControls;
                using System.Web.UI.W ebControls.WebP arts;
                using System.Web.UI.H tmlControls;

                /// <summary>
                /// Summary description for User
                /// </summary>
                public class User
                {
                public User()
                {
                //
                // TODO: Add constructor logic here
                //
                }
                }
                [/code]

                I am assuming here that you are using C#. If it is VB .Net, tell me and I will change the code.

                Anyways, from within that above code snippet, you would add variables and it would start to look similiar to:

                [code=cpp]
                public class User
                {
                private string _FirstName, _LastName, _Address;

                public string Address
                {
                get { return _Address; }
                set { _Address = value; }
                }

                public string LastName
                {
                get { return _LastName; }
                set { _LastName = value; }
                }

                public string FirstName
                {
                get { return _FirstName; }
                set { _FirstName = value; }
                }

                public User()
                {
                //
                // TODO: Add constructor logic here
                //
                }
                }
                [/code]


                **NOTE** If you are unfamiliar with C#, tell me so I will take a few steps back and explain some C# for you.

                Comment

                • TRScheel
                  Recognized Expert Contributor
                  • Apr 2007
                  • 638

                  #9
                  Also, if you need C# help, tell me roughly what you do know so I dont go over old information.

                  Comment

                  • parshupooja
                    New Member
                    • Jun 2007
                    • 159

                    #10
                    Hi,

                    Thanks again. actually I am new to Asp.net C#, its been few months only. Here is a User.cs file
                    [code=cpp]

                    using System;
                    using System.Data;
                    using System.Configur ation;
                    using System.Web;
                    using System.Web.Secu rity;
                    using System.Web.UI;
                    using System.Web.UI.W ebControls;
                    using System.Web.UI.W ebControls.WebP arts;
                    using System.Web.UI.H tmlControls;

                    /// <summary>
                    /// Summary description for User
                    /// </summary>
                    public class User
                    {
                    private string _FirstName, _LastName, _Title, _Email, _Phone, _Company, _Address, _City, _State, _Zip, _Country, _Other;

                    public User() { }

                    public string FirstName
                    {
                    get { return _FirstName; }
                    set { _FirstName = value; }
                    }

                    public string LastName
                    {
                    get { return _LastName; }
                    set { _LastName = value; }
                    }

                    public string Title
                    {

                    get { return _Title; }
                    set { _Title = value; }
                    }
                    public string Email
                    {
                    get { return _Email; }
                    set { _Email = value; }

                    }
                    public string Phone
                    {

                    get { return _Phone; }
                    set { _Phone = value; }
                    }
                    public string Company
                    {

                    get { return _Company; }
                    set { _Company = value; }
                    }
                    public string Address
                    {
                    get { return _Address; }
                    set { _Address = value; }
                    }

                    public string City
                    {

                    get { return _City; }
                    set { _City = value; }

                    }

                    public string State
                    {

                    get { return _State; }
                    set { _State = value; }
                    }

                    public int Zip
                    {

                    get { return _Zip; }
                    set { _Zip = value; }
                    }

                    public string Country
                    {

                    get { return _Country; }
                    set { _Country = value; }
                    }

                    public string Other
                    {

                    get { return _Other; }
                    set { _Other = value; }
                    }

                    public enum InterestedIn
                    {
                    Training = 1,
                    Activity = 2,
                    Learning = 4
                    }

                    public enum ReferredFrom
                    {
                    Email,
                    DirectMail,
                    Referral,
                    Publication,
                    Tradeshow,
                    WebsiteLink,
                    Internet
                    }

                    public User_Input SQLGetParameter s()
                    {
                    SqlParameter[] aspParams = new SqlParameter[0];

                    }

                    }
                    [/code]


                    I am not sure whether its correct, have a look at it and let me know wat should be done next. appreciate your efforts.

                    Comment

                    • TRScheel
                      Recognized Expert Contributor
                      • Apr 2007
                      • 638

                      #11
                      You've defined the enums, but you have no instances of them within the class, Make sure to have that.

                      Also the SqlParameters function should return an array of SqlParamter (or, SqlParamter[])

                      Comment

                      • parshupooja
                        New Member
                        • Jun 2007
                        • 159

                        #12
                        I hope this is correct as far as enums are concerned but still i am unable to grasp SQLParameter part. Could you please show that to me and verify this too.

                        Thanks for being patient and helping me toward this.
                        [code=cpp]
                        using System;
                        using System.Data;
                        using System.Configur ation;
                        using System.Web;
                        using System.Web.Secu rity;
                        using System.Web.UI;
                        using System.Web.UI.W ebControls;
                        using System.Web.UI.W ebControls.WebP arts;
                        using System.Web.UI.H tmlControls;

                        /// <summary>
                        /// Summary description for User
                        /// </summary>
                        public class User
                        {
                        private string _FirstName, _LastName, _Title, _Email, _Phone, _Company, _Address, _City, _State, _Zip, _Country, _Other;

                        public User() { }

                        public string FirstName
                        {
                        get { return _FirstName; }
                        set { _FirstName = value; }
                        }

                        public string LastName
                        {
                        get { return _LastName; }
                        set { _LastName = value; }
                        }

                        public string Title
                        {

                        get { return _Title; }
                        set { _Title = value; }
                        }
                        public string Email
                        {
                        get { return _Email; }
                        set { _Email = value; }

                        }
                        public string Phone
                        {

                        get { return _Phone; }
                        set { _Phone = value; }
                        }
                        public string Company
                        {

                        get { return _Company; }
                        set { _Company = value; }
                        }
                        public string Address
                        {
                        get { return _Address; }
                        set { _Address = value; }
                        }

                        public string City
                        {

                        get { return _City; }
                        set { _City = value; }

                        }

                        public string State
                        {

                        get { return _State; }
                        set { _State = value; }
                        }

                        public string Zip
                        {

                        get { return _Zip; }
                        set { _Zip = value; }
                        }

                        public string Country
                        {

                        get { return _Country; }
                        set { _Country = value; }
                        }

                        public string Other
                        {

                        get { return _Other; }
                        set { _Other = value; }
                        }

                        public enum InterestedIn
                        {
                        Training = 1,
                        Activity = 2,
                        Learning = 4
                        }
                        private InterestedIn Inti = InterestedIn.Tr aining;
                        private string myinterest = string.Empty;

                        public string finterest
                        {
                        get { return this.myinterest ; }
                        set { this.myinterest = (string)value; }
                        }

                        public InterestedIn interesttype
                        {
                        get { return this.Inti; }
                        set { this.Inti = (myinterest)val ue; }
                        }

                        public enum ReferredFrom
                        {
                        Email,
                        DirectMail,
                        Referral,
                        Publication,
                        Tradeshow,
                        WebsiteLink,
                        Internet
                        }

                        private ReferredFrom RF = ReferredFrom.Em ail;
                        private string refer = string.Empty;

                        public string ReferredMedia
                        {
                        get { return this.refer; }
                        set { this.refer = (string)value; }
                        }

                        public ReferredFrom refertype
                        {
                        get { return this.RF; }
                        set { this.RF = refer)value; }
                        }


                        }[/code]

                        Comment

                        • TRScheel
                          Recognized Expert Contributor
                          • Apr 2007
                          • 638

                          #13
                          Ok, some changes should be made just to make it easier to read. First off, put all your private variables and public enum declarations at the top of the class. Then, you should have one instance of the two enums, as shown below. I wasnt exactly sure what you were going with for the string versions of them, but if you take ReferredFrom.In ternet.ToString () it will return 'Internet'. If you want to have public versions of those enums so you dont need to add .ToString() to it, go for it, but thats how to get it.

                          Now onto that SQLParameter function. The start of it is included at the end. Take a look and see if you understand what is going on.

                          Now here is some styling information. Why a function for the sql parameters instead of a read only property? Well, technically, its not returning a private variable. It is actually doing work, then returning that value. The reason we used properties before is so that if we changed how LastName worked, for instance, we only had to change it in the User class. We want the end user to realize that by calling GetSqlParameter s() it will do work, not just expose a variable to them. Others will have different opinions on the matter, and in my opinion, there is no right or wrong way, I just attempt to remain consistent in my work and I suggest you try to retain a consistency in your work. It will help you and others that use your work.

                          When you are done and have no further questions about this portion, I will help you move onto the next step.

                          [code=cpp]
                          using System;
                          using System.Data;
                          using System.Configur ation;
                          using System.Web;
                          using System.Web.Secu rity;
                          using System.Web.UI;
                          using System.Web.UI.W ebControls;
                          using System.Web.UI.W ebControls.WebP arts;
                          using System.Web.UI.H tmlControls;
                          using System.Data.Sql Client;
                          using System.Collecti ons.Generic;

                          /// <summary>
                          /// Summary description for User
                          /// </summary>
                          public class User
                          {
                          public enum InterestedIn
                          {
                          Training = 1,
                          Activity = 2,
                          Learning = 4
                          }

                          public enum ReferredFrom
                          {
                          Email,
                          DirectMail,
                          Referral,
                          Publication,
                          Tradeshow,
                          WebsiteLink,
                          Internet
                          }


                          private ReferredFrom _ReferredFrom;
                          private InterestedIn _InterestedIn;
                          private string _FirstName, _LastName, _Title, _Email, _Phone, _Company, _Address, _City, _State, _Zip, _Country, _Other;

                          public User() { }

                          public ReferredFrom UserReferredFro m
                          {
                          get { return _ReferredFrom; }
                          set { _ReferredFrom = value; }
                          }

                          public InterestedIn UserInterestedI n
                          {
                          get { return _InterestedIn; }
                          set { _InterestedIn = value; }
                          }

                          public string FirstName
                          {
                          get { return _FirstName; }
                          set { _FirstName = value; }
                          }

                          public string LastName
                          {
                          get { return _LastName; }
                          set { _LastName = value; }
                          }

                          public string Title
                          {
                          get { return _Title; }
                          set { _Title = value; }
                          }
                          public string Email
                          {
                          get { return _Email; }
                          set { _Email = value; }

                          }
                          public string Phone
                          {
                          get { return _Phone; }
                          set { _Phone = value; }
                          }
                          public string Company
                          {
                          get { return _Company; }
                          set { _Company = value; }
                          }
                          public string Address
                          {
                          get { return _Address; }
                          set { _Address = value; }
                          }

                          public string City
                          {
                          get { return _City; }
                          set { _City = value; }
                          }

                          public string State
                          {
                          get { return _State; }
                          set { _State = value; }
                          }

                          public string Zip
                          {
                          get { return _Zip; }
                          set { _Zip = value; }
                          }

                          public string Country
                          {
                          get { return _Country; }
                          set { _Country = value; }
                          }

                          public string Other
                          {
                          get { return _Other; }
                          set { _Other = value; }
                          }

                          public SqlParameter[] GetSqlParameter s()
                          {
                          List<SqlParamet er> SqlParameters = new List<SqlParamet er>();

                          SqlParameters.A dd(new SqlParameter("F irstName", this.FirstName) );
                          SqlParameters.A dd(new SqlParameter("L astName", this.LastName)) ;
                          //... continue through the entire class

                          return SqlParameters.T oArray();
                          }
                          }
                          [/code]

                          Comment

                          • parshupooja
                            New Member
                            • Jun 2007
                            • 159

                            #14
                            Thank You for being so patient with me. Here it is
                            [code=cpp]
                            using System;
                            using System.Data;
                            using System.Configur ation;
                            using System.Web;
                            using System.Web.Secu rity;
                            using System.Web.UI;
                            using System.Web.UI.W ebControls;
                            using System.Web.UI.W ebControls.WebP arts;
                            using System.Web.UI.H tmlControls;
                            using System.Data.Sql Client;
                            using System.Collecti ons.Generic;

                            /// <summary>
                            /// Summary description for User
                            /// </summary>
                            public class User
                            {
                            public enum InterestedIn
                            {
                            Training = 1,
                            Activity = 2,
                            Learning = 4
                            }

                            public enum ReferredFrom
                            {
                            Email,
                            DirectMail,
                            Referral,
                            Publication,
                            Tradeshow,
                            WebsiteLink,
                            Internet
                            }


                            private ReferredFrom _ReferredFrom;
                            private InterestedIn _InterestedIn;
                            private string _FirstName, _LastName, _Title, _Email, _Phone, _Company, _Address, _City, _State, _Zip, _Country, _Other;

                            public User() { }

                            public ReferredFrom UserReferredFro m
                            {
                            get { return _ReferredFrom; }
                            set { _ReferredFrom = value; }
                            }

                            public InterestedIn UserInterestedI n
                            {
                            get { return _InterestedIn; }
                            set { _InterestedIn = value; }
                            }

                            public string FirstName
                            {
                            get { return _FirstName; }
                            set { _FirstName = value; }
                            }

                            public string LastName
                            {
                            get { return _LastName; }
                            set { _LastName = value; }
                            }

                            public string Title
                            {
                            get { return _Title; }
                            set { _Title = value; }
                            }
                            public string Email
                            {
                            get { return _Email; }
                            set { _Email = value; }

                            }
                            public string Phone
                            {
                            get { return _Phone; }
                            set { _Phone = value; }
                            }
                            public string Company
                            {
                            get { return _Company; }
                            set { _Company = value; }
                            }
                            public string Address
                            {
                            get { return _Address; }
                            set { _Address = value; }
                            }

                            public string City
                            {
                            get { return _City; }
                            set { _City = value; }
                            }

                            public string State
                            {
                            get { return _State; }
                            set { _State = value; }
                            }

                            public string Zip
                            {
                            get { return _Zip; }
                            set { _Zip = value; }
                            }

                            public string Country
                            {
                            get { return _Country; }
                            set { _Country = value; }
                            }

                            public string Other
                            {
                            get { return _Other; }
                            set { _Other = value; }
                            }

                            public SqlParameter[] GetSqlParameter s()
                            {
                            List<SqlParamet er> SqlParameters = new List<SqlParamet er>();

                            SqlParameters.A dd(new SqlParameter("F irstName", this.FirstName) );
                            SqlParameters.A dd(new SqlParameter("L astName", this.LastName)) ;
                            SqlParameters.A dd(new SqlParameter("T itle", this.Title));
                            SqlParameters.A dd(new SqlParameter("E mail", this.Email));
                            SqlParameters.A dd(new SqlParameter("P hone", this.Phone));
                            SqlParameters.A dd(new SqlParameter("C ompany", this.Company));
                            SqlParameters.A dd(new SqlParameter("A ddress", this.Address));
                            SqlParameters.A dd(new SqlParameter("C ity", this.City));
                            SqlParameters.A dd(new SqlParameter("S tate", this.State));
                            SqlParameters.A dd(new SqlParameter("Z ip", this.Zip));
                            SqlParameters.A dd(new SqlParameter("C ountry", this.Country));
                            SqlParameters.A dd(new SqlParameter("O ther", this.Other));
                            SqlParameters.A dd(new SqlParameter("Z ip", this.Zip));
                            SqlParameters.A dd(new SqlParameter("U serReferedFrom" , this.UserReferr edFrom));
                            SqlParameters.A dd(new SqlParameter("U serInterestedIn ", this.UserIntere stedIn));


                            return SqlParameters.T oArray();
                            }
                            }[/code]

                            Comment

                            • TRScheel
                              Recognized Expert Contributor
                              • Apr 2007
                              • 638

                              #15
                              Ok, now for some SQL fun. Do you have some background knowledge of SQL or would you like me to start from the beginning?

                              Comment

                              Working...