Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • Asp.net Registration Form, need email validation in C#
AuthorQuestion
Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        

    }
    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Clear_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
        TextBox9.Text = "";
        TextBox10.Text = "";
        TextBox11.Text = "";
        RadioButtonList1.SelectedValue = null;
        TextBox12.Text = "";
        DropDownList4.SelectedValue = null;
        DropDownList5.SelectedValue = null;
        CheckBox1.Checked = false;
        Label21.Text = "";
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataReader dr;
        SqlConnection con = new SqlConnection("Data Source=SARANYA-TS02\\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("insert into RegistrationForm values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text
            + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + RadioButtonList1.SelectedValue
            + "','" + TextBox12.Text + "','" + TextBox9.Text + "','" + TextBox10.Text
            + "','" + TextBox11.Text + "','" + DropDownList4.SelectedValue + "','" + DropDownList5.SelectedValue + "')", con);
        con.Open();
        cmd.ExecuteNonQuery();
        SqlCommand cc = new SqlCommand("select from RegistrionForm where e-mail Address");
        cc.ExecuteNonQuery();
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        
    }
    protected void TextBox7_TextChanged(object sender, EventArgs e)
    {
        
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox9_TextChanged(object sender, EventArgs e)
    {

    }
}





 this is my code i want to modify n email id... after i click submit button if that email id is already exists means i ve to throw exception.... plz help me

AuthorReply
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
Actaully i need code for c# 3.5 to store that values in sql db 2008.... In E mail block i need to throw exception.... like this email id is already exists.
i didnt use grid view n all.. plz help me....

Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
try this code:

      string Sqlquery = "SELECT * FROM RegistrationForm where EmailId='" + txtEmailid.Text + "'";
       SqlCommand com = new SqlCommand("Sqlquery", con);
       SqlDataReader reader = new SqlDataReader();
       con.Open();
       reader = com.ExecuteReader;
try
{
      if (!reader.Read)
        {
                SqlCommand cmd = new SqlCommand("insert into RegistrationForm values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text
            + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + RadioButtonList1.SelectedValue
            + "','" + TextBox12.Text + "','" + TextBox9.Text + "','" + TextBox10.Text
            + "','" + TextBox11.Text + "','" + DropDownList4.SelectedValue + "','" + DropDownList5.SelectedValue + "')", con);
        con.Open();
        cmd.ExecuteNonQuery();
        }
     else
      {
              MessageBox.Show (" EmailId already exists");
      }
     reader.Close();
     con.Close();
}
catch(Exception ex)
{
         MessageBox.Show(ex.Message);
     }






Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
Error8The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined this error s coming... in SqlDataReader reader=new SqlDataReader(); wat to do now????? and also without giving sql connection string how the values ll get enter in db???????
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
Hi, i can run the program but still i ve error after i enter all the values... the error is: Could not find stored procedure 'Sqlquery'.plz tel me how to solve this....
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
change this line as

 SqlCommand com = new SqlCommand(Sqlquery, con);



Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
before try block replace this code as.

 string Sqlquery = "SELECT * FROM RegistrationForm where EmailId='" + txtEmailid.Text + "'";
       SqlCommand com = new SqlCommand(Sqlquery, con);
      con.Open();
       SqlDataReader reader =  com.ExecuteReader();


Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
i got other error... actually i ve used emailid in sql db is E-mail Address like wise i ve used in coding also but in that line i got error... the error is : An expression of non-boolean type specified in a context where a condition is expected, near 'Address'.
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
good ,if your problem solve than mark this answer as accepted that will be help any other people  who have same type problems.
Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
i got other error... actually i ve used emailid in sql db is E-mail Address like wise i ve used in coding also but in that line i got error... the error is : An expression of non-boolean type specified in a context where a condition is expected, near 'Address'.
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
after i enter all the values in form i got this error: ExecuteReader requires an open and available Connection. The connection's current state is closed.
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012  
can a give your code.
Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 11 Dec 2012  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        

    }
    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Clear_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
        TextBox9.Text = "";
        TextBox10.Text = "";
        TextBox11.Text = "";
        RadioButtonList1.SelectedValue = null;
        TextBox12.Text = "";
        DropDownList4.SelectedValue = null;
        DropDownList5.SelectedValue = null;
        CheckBox1.Checked = false;
        Label21.Text = "";
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=SARANYA-TS02\\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
        string Sqlquery = "SELECT * FROM RegistrationForm where E-mail Address=" + TextBox7.Text + "'";
        SqlCommand com = new SqlCommand(Sqlquery, con);
        SqlDataReader reader = com.ExecuteReader();
        con.Open();
        try
        {
            if (!reader.Read())
            {
                SqlCommand cmd = new SqlCommand("insert into RegistrationForm values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text
            + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + RadioButtonList1.SelectedValue
            + "','" + TextBox12.Text + "','" + TextBox9.Text + "','" + TextBox10.Text
            + "','" + TextBox11.Text + "','" + DropDownList4.SelectedValue + "','" + DropDownList5.SelectedValue + "')", con);
                con.Open();
                cmd.ExecuteNonQuery();
            }
            else
            {
                MessageBox.Show(" EmailId already exists");
            }
            reader.Close();
            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        
    }
    protected void TextBox7_TextChanged(object sender, EventArgs e)
    {
        
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox9_TextChanged(object sender, EventArgs e)
    {

    }
}

Vishnujeet Kumar
  • 0
  • 0
accepted
Re: Asp.net Registration Form, need email validation in C#
Posted By Vishnujeet Kumar on 11 Dec 2012   Accepted Answer
try this: 



SqlConnection con = new SqlConnection("Data Source=SARANYA-TS02\\SQLEXPRESS;Initial Catalog=ss;Integrated Security=True");
        string Sqlquery = "SELECT * FROM RegistrationForm where E-mail_Address=" + TextBox7.Text + "'";
       con.Open();       
       SqlCommand com = new SqlCommand(Sqlquery, con);
        SqlDataReader reader = com.ExecuteReader();
       
        try
        {
            if (!reader.Read())
            {
                SqlCommand cmd = new SqlCommand("insert into RegistrationForm values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text
            + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + RadioButtonList1.SelectedValue
            + "','" + TextBox12.Text + "','" + TextBox9.Text + "','" + TextBox10.Text
            + "','" + TextBox11.Text + "','" + DropDownList4.SelectedValue + "','" + DropDownList5.SelectedValue + "')", con);
           
                cmd.ExecuteNonQuery();
            }
            else
            {
                MessageBox.Show(" EmailId already exists");
            }
            reader.Close();
            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

Thanks & Regards, Vishnujeet
Re: Asp.net Registration Form, need email validation in C#
Posted By saranya S on 12 Dec 2012  
iam getting this error: An expression of non-boolean type specified in a context where a condition is expected, near 'Address'.

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.