Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > checking if id and reg already exists

Thread Tools

checking if id and reg already exists

PetroTiburcio PetroTiburcio is offline
Junior Member
Join Date: May 2013
Posts: 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.

SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
        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;


        SqlDataReader reader = cmdd.ExecuteReader();

            if (reader.HasRows)
                MessageBox("User Id/Registry Number already exists");

                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;
            	MessageBox("successfully saved!");
Any help would be appreciated. I am using c# with Thank you in advance and God Bless.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM reporting and UML tools - what exists already? J Peyret Python 3 02-14-2008 01:31 PM
JDBC: Checking if a unique column already exists during insertion priyom Java 1 10-05-2006 11:17 AM
finding if file exists or not in apache webdav server and if exists what is the mime type of it.... Totan Java 0 04-17-2006 05:13 AM
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM