checking if id and reg already exists

Discussion in 'ASP .Net Web Controls' started by PetroTiburcio, Jun 5, 2013.

  1. PetroTiburcio

    PetroTiburcio

    Joined:
    May 17, 2013
    Messages:
    7
    Hi, I have this table Profile which has fields with user_Id and regNo and I want to check first if id and email are already exists before proceed to inserting datas. In my codes, I am able to validate only one row (either id or reg number), but if I am going to validate the two of them, it gives me an error, saying "Must declare the scalar variable @userid". I dont know if it is with my select that is wrong or something in my codes.

    Code:
    SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
            con.Open();
            SqlCommand cmdd = new SqlCommand("select * from Profile where user_Id = @userid AND RegNo = @reg", con);
            
            SqlParameter param = new SqlParameter();
            //SqlParameter param1 = new SqlParameter();
            param.ParameterName = "@userid";
            param.ParameterName = "@reg";
    
            param.Value = txtid.Text;
            param.Value = txtregNo.Text;
    
            cmdd.Parameters.Add(param);
            //cmdd.Parameters.Add(param1);
    
            
            SqlDataReader reader = cmdd.ExecuteReader();
    
           
                if (reader.HasRows)
                {
                    MessageBox("User Id/Registry Number already exists");
                }
    
    
                else
                {
                    SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
                	SqlCommand cmd = new SqlCommand("qry", con);
                	cmd.CommandType = System.Data.CommandType.Text;
    
                	cmd.Parameters.AddWithValue("@id", txtid.Text);
                	cmd.Parameters.AddWithValue("@regno", txtregNo.Text);
                	cmd.Parameters.AddWithValue("@name", txtname.Text);
          
                	cmd.CommandType = System.Data.CommandType.StoredProcedure;
                	con.Open();
                	cmd.ExecuteNonQuery();
                	MessageBox("successfully saved!");
                
                }
    Any help would be appreciated. I am using c# with asp.net. Thank you in advance and God Bless.
    PetroTiburcio, Jun 5, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad Crowder
    Replies:
    7
    Views:
    21,500
    hemant.yadav
    Oct 24, 2009
  2. Alvin Bruney [MVP]

    Re: Class already exists ... help please!!

    Alvin Bruney [MVP], Apr 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,482
    Alvin Bruney [MVP]
    Apr 6, 2004
  3. Totan
    Replies:
    0
    Views:
    924
    Totan
    Apr 17, 2006
  4. priyom
    Replies:
    1
    Views:
    1,247
    timoi
    Oct 5, 2006
  5. J Peyret
    Replies:
    3
    Views:
    364
    Bruno Desthuilliers
    Feb 14, 2008
Loading...

Share This Page