Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Below is the web form which should allow only two entries per month. Data is inserting But I have no idea how to validate only two entries per month.

This is what I have done so far..


C#
protected void btnSubmit_Click(object sender, EventArgs e)
        {
           
            Hashtable empSession = (Hashtable)Session["UserDetails"];
            employeeno = Convert.ToInt32(empSession["EmpNo"]);
            int slno = Convert.ToInt32(get_max("select max(ID) from WFHCO_RQST")) + 1;
            string k;
            k = slno.ToString();
            string REQ_ID = "REQ" + k;
            string EMPNO = (from i in context.CLM_EMPLOYEE_MSTs
                           where i.EMPNO.Equals(Convert.ToInt32(empSession["EmpNo"].ToString()))
                           select i.EMPNO).SingleOrDefault().ToString();
            string FDate = TextBox2.Text;
            string TDate = TextBox3.Text;
            conn.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO WFHCO_RQST (PROJ_CODE,EMPNO,REQ_TYPE,STATUS,FROM_DATE,NAME,TO_DATE,NO_OF_DAYS,REASON,REQ_ID)VALUES('" + DropDownList2.SelectedValue.ToString() + "','" + EMPNO + "','" + DropDownList1.SelectedValue.ToString() + "','Awaiting Approval','" + TextBox2.Text.Trim() + "','" + TextBox3.Text.Trim() + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + REQ_ID + "')", conn);
            
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            conn.Close();
Posted
Updated 3-Dec-15 18:19pm
v3

1 solution

Two option for you.
1. get count of this month entry in your table - for this you can use count()
2. Manage a flag - create another table which have two columns 1. flag and 2. month - when you insert your table you also have to update your flag in this table and check this flag values before you insert in WFHCO_RQST table.

Thanks
AARIF SHAIKH
 
Share this answer
 
Comments
Member 9017207 4-Dec-15 0:26am    
I would like to go for option one. Can u help me write the query? I'm a newbie. Sorry
aarif moh shaikh 4-Dec-15 0:31am    
have you insert current month (date) in your table ?
Member 9017207 4-Dec-15 0:32am    
I am just inserting to date and from date
aarif moh shaikh 4-Dec-15 0:38am    
Try this. (it will give you count)

select count(1) from WFHCO_RQST where month(from_date) = month(getdate())
Member 9017207 4-Dec-15 1:21am    
Its not giving count :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900