예제 #1
0
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            Regex MY_EXP = new Regex("^(1[A-Z][A-Z]1)[3-6][A-Z][A-Z](([0-9][0-9][1-9])|([0-9][1-9][0-9])|([1-9][0-9][0-9]))*$");
            Match nmat   = MY_EXP.Match(regusn.Text);

            if (regusn.Text.Equals("") || regname.Text.Equals("") || regcol.Text.Equals("") || eventname.Text.Equals(""))
            {
                MessageBox.Show("Fields cannot be empty");
            }
            else if (!nmat.Success)
            {
                MessageBox.Show("Enter valid USN");
            }
            else
            {
                string        sql  = "select eid from events where ename = '" + eventname.Text + "'";
                SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\HarishChandra\Documents\Visual Studio 2010\Projects\utsav\utsav\utsavbms.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
                conn.Open();
                SqlCommand    cmd1 = new SqlCommand(sql, conn);
                SqlDataReader DR   = cmd1.ExecuteReader();
                String        s    = "";
                while (DR.Read())
                {
                    s = (DR[0].ToString());
                }
                string p = regusn.Text + s;
                DR.Close();
                string     Sql = "insert into participants values ('" + regusn.Text + "' , '" + regname.Text + "' ,'" + s + "', '" + eventname.Text + "' , '" + regcol.Text + "','" + p + "')";
                SqlCommand cmd = new SqlCommand(Sql, conn);
                int        a   = cmd.ExecuteNonQuery();
                if (a == 0)
                {
                    MessageBox.Show("Invalid Data");
                }
                else
                {
                    MessageBox.Show("Registered Successfully..!!!! :)");
                }
                this.Hide();
                home gh = new home();
                gh.Show();
            }
        }