none
User cannot submit daily report twice in a day?? RRS feed

  • Question

  • hello all,

                 Actually  when user submit report in a day,user  again  submit  report in the  same day.. but i want user cannot submit the report twice in the same day ?? please help me..

    my code is:

                               SqlCommand comm = new SqlCommand("SELECT * FROM REPORT WHERE username='" + Label2.Text + "' and date=(SELECT Today=convert(varchar, GETDATE(), 101)) ", con);
                SqlDataReader dr = comm.ExecuteReader();
                if (dr.HasRows)
                {
                    Aaleert.Show("You can't submit the report twice in a day..............................");



                }
                else
                {
                    dr.Close();
                    SqlCommand cmd = new SqlCommand("INSERT INTO REPORT(username,report,date) SELECT '" + Label2.Text + "','" + TextBox1.Text + "',GETDATE()", con);

                    cmd.ExecuteNonQuery();
    Monday, July 16, 2012 6:06 AM

Answers

  • Your SQL statement will return a string date value in the format MM/DD/YYYY (e.g. 07/16/2012). Is this the format of the date in your Label?

    It's usually recommend that date values be compared in their native numeric format rather than as string/text values.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, July 16, 2012 12:19 PM