Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Beginner question

    Hi all, i'm started trying ASP today, im trying to do this tutorial, about storing stuff in database.
    But im getting confused by the different languages in there

    what do i do with this code (does it go in default.aspx where the HTML is??):

    Code:
    private void ExecuteInsert(string name, string username, string password, string gender, string age, string address)
        {
            SqlConnection conn = new SqlConnection(GetConnectionString());
            string sql = "INSERT INTO tblRegistration (Name, UserName, Password, Gender, Age, Address) VALUES "
                        + " (@Name,@UserName,@Password,@Gender,@Age,@Address)";
    
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlParameter[] param = new SqlParameter[6];
                //param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
                param[0] = new SqlParameter("@Name", SqlDbType.VarChar, 50);
                param[1] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
                param[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                param[3] = new SqlParameter("@Gender", SqlDbType.Char, 10);
                param[4] = new SqlParameter("@Age", SqlDbType.Int, 100);
                param[5] = new SqlParameter("@Address", SqlDbType.VarChar, 50);
                
                param[0].Value = name;
                param[1].Value = username;
                param[2].Value = password;
                param[3].Value = gender;
                param[4].Value = age;
                param[5].Value = address;
    
                for (int i = 0; i < param.Length; i++)
                {
                    cmd.Parameters.Add(param[i]);
                }
    
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                string msg = "Insert Error:";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                conn.Close();
            }
    }
    http://geekswithblogs.net/dotNETvinz...n-asp.net.aspx

    thx in advance for your help

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    60
    Thanks
    65
    Thanked 0 Times in 0 Posts
    Put it in the code behind


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •