0

i m trying to code my registration page in c#... I m trying to insert data in database but when i run my program it is actually not inserting data in database. i don't have much knowledge about c#.. so i can't figure out what's the problem here.. Anybody please tell me the issue

 public partial class Register : System.Web.UI.Page
{
    public string GetConnectionString()
    {
        return System.Configuration.ConfigurationManager.ConnectionStrings
           ["RegisterConnectionString1"].ConnectionString;
    }

    private void execution(string UserID, string Fname, string Lname, string Fathername, string Password, string CPassword, string Email)
    {
        SqlConnection conn = new SqlConnection(GetConnectionString());
        string sql = "INSERT INTO [Table] (UserID, Fname, Lname, Fathername, Password, CPassword, Email) VALUES "
        + " (@UserID , @Fname, @Lname, @Fathername, @Password, @CPassword, @Email)";
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] pram = new SqlParameter[7];
            pram[0] = new SqlParameter("@UserID", SqlDbType.VarChar, 50);
            pram[1] = new SqlParameter("@Fname", SqlDbType.VarChar, 50);
            pram[2] = new SqlParameter("@Lname", SqlDbType.VarChar, 50);
            pram[3] = new SqlParameter("@Fathername", SqlDbType.VarChar, 50);
            pram[4] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
            pram[5] = new SqlParameter("@CPassword", SqlDbType.VarChar, 50);
            pram[6] = new SqlParameter("@Email", SqlDbType.VarChar, 50);
            pram[0].Value = UserID;
            pram[1].Value = Fname;
            pram[2].Value = Lname;
            pram[3].Value = Fathername;
            pram[4].Value = Password;
            pram[5].Value = CPassword;
            pram[6].Value = Email;
            for (int i = 0; i < pram.Length; i++)
            {
                cmd.Parameters.Add(pram[i]);
            }
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex_msg)
        {
            string msg = "Error occured while inserting";
            msg += ex_msg.Message;
            throw new Exception(msg);
        }
        finally
        {
            //Here will be fially elements
            conn.Close();
        }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
        this.Form.Target = "_blank";
    }

    protected void Buttonregister_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            Response.Write("Please complete the form.");

        }
        else
        {
            Response.Redirect("Home.aspx");
        }
    }
}
amalnoor
  • 1
  • 1
  • Where you are calling `execution(...)` function? – Sankar Feb 21 '17 at 16:26
  • If you don't give you any error but the data not appear in table maybe your problem is this: http://stackoverflow.com/questions/31604951/sql-command-insert-is-working-but-the-data-not-appear-in-table – Salah Akbari Feb 21 '17 at 16:28
  • { execution(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text); Confirm.Visible = true; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; } – amalnoor Feb 21 '17 at 16:36
  • its working now.. thank u for your help :) – amalnoor Feb 21 '17 at 16:48

0 Answers0