...

View Full Version : ASP Beginner question



Baatus
05-04-2012, 03:18 PM
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??):



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/archive/2009/04/30/creating-a-simple-registration-form-in-asp.net.aspx

thx in advance for your help

code-in-time
05-27-2012, 11:44 AM
Put it in the code behind



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum