Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:34:30+00:00 2026-06-12T16:34:30+00:00

I have a details view that I am using to fill a table with

  • 0

I have a details view that I am using to fill a table with values. It is now inserting values correctly but I needed to now check to see if the user is trying to enter a new record that would interfere with the previous records.

If A user enters a new event that falls on 2012-12-12 but that same user has already entered a record for 2012-12-12 then i would like an error to be thrown and the record not able to be inserted.

Just checking for a unique record of the time wont work because a different user can create an even 2012-12-12 and it will be acceptable. Only the same user cannot create the same events dates. So I know I need to check two of the fields in the table but I was unsure of how to do this checking in my code.

For example:

user 1 new event 2012-12-12 —– ok

user 2 new event 2012-12-12 —– ok

user 3 new event 2012-12-12 —– ok

user 2 new event 2012-12-12 —– should throw an error and not allow that record to be created.

user 3 new event 2012-10-12 —– ok

EDITED

Currently I am using this to update the table:

   public void UpdateForm(Int64 requestid,
                              Decimal empid,
                              String leave,
                              DateTime startdate,
                              DateTime enddate,
                              String starttime,
                              String endtime,
                              String standby,
                              String status,
                              String rsn,
                              String remarks,
                              String approver,
                              String with,
                              String reqleave,
                              String FIRSTNAME,
                              String LASTNAME)
    {

        var CurrUser = "a03       ";

        Account.Login uusr = new Account.Login();
        CurrUser = uusr.User.Identity.Name.ToString().ToUpper();

        var sql = "update TIME.request set empid=@empid, leave=@leave, with=@with, startdate=@startdate, reqleave=@reqleave, enddate=@enddate, starttime=@starttime, endtime=@endtime, standby=@standby, status=@status, rsn=@rsn, remarks=@remarks, approver=@approver where requestid = @requestid";

        using (iDB2Connection conn = new iDB2Connection(GetConnectionString()))
        {
            conn.Open();

            using (iDB2Command cmd = new iDB2Command(sql, conn))
            {
                cmd.DeriveParameters();
                cmd.Parameters["@requestid"].Value = requestid;
                cmd.Parameters["@empid"].Value = empid;
                cmd.Parameters["@leave"].Value = leave;
                cmd.Parameters["@startdate"].Value = startdate;
                cmd.Parameters["@enddate"].Value = enddate;
                cmd.Parameters["@starttime"].Value = starttime;
                cmd.Parameters["@endtime"].Value = endtime;
                cmd.Parameters["@standby"].Value = standby;
                cmd.Parameters["@status"].Value = status;
                cmd.Parameters["@rsn"].Value = rsn;
                cmd.Parameters["@remarks"].Value = remarks;
                cmd.Parameters["@approver"].Value = approver;
                cmd.Parameters["@reqleave"].Value = reqleave;
                cmd.Parameters["@with"].Value = with;

                cmd.ExecuteNonQuery();
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:34:32+00:00Added an answer on June 12, 2026 at 4:34 pm

    Create a stored procedure and have an output parameter, check if the item your inserting exists:

    if exists(select 1 from table where user = @user and eventtime = @eventtime)
      begin
        set @output = 'event already exists'
      end 
    else
     begin
        --Prevent DBNull output, see comments
        set @output = ''
       --Insert into table
     end
    

    Add an output parameter to the procedure through C#

      var output = new SqlParameter() { Direction = ParameterDirection.Output, ParameterName = "@Output" };
      var cmd = new SqlCommand("procname", connection)
      cmd.Parameters.Add(output);
      //Add other params
      cmd.ExecuteNonQuery();
      if (!string.IsNullOrEmpty(output.Value))
        //Handle the error
        throw new Exception("Already exists");
    

    A stored procedure in SQL is what you are looking for with the relevant parameters following the above, comment if there is something you don’t understand.

    EDIT: How to create and call a procedure

    CREATE PROCEDURE [dbo].[Prefix_SomeProcName]
    
    --Parameters you need from the front end
    @User varchar(50),
    @EventTime datetime,
    @Output varchar(100) output
    
    --Created by: Your name
    --Created date: Todays date
    --Description: To do some stuff
    
    AS
    
    --Do your stuff here
    if exists(select 1 from table where user = @user and eventtime = @eventtime)
      begin
        set @output = 'event already exists'
      end 
    else
     begin
        --Prevent DBNull output, see comments
        set @output = ''
       --Insert into table
     end
    

    Then you need a to import System.Data.SqlClient and do the following.

    using(SqlConnection con = New SqlConnection("ConnectionString")
    {
       SqlCommand cmd = new SqlCommand("Prefix_SomeProcName", con);
       cmd.CommandType = CommandType.StoredProcedure;
       var output = new SqlParameter() { Direction = ParameterDirection.Output, ParameterName = "@Output" };
       //Add your other parameters
       SqlDataAdapter sda = new SqlDataAdapter(cmd);
       DatatTable dt = New DataTable();
       sda.Fill(dt);
    }
    

    The DataTable will now have the contents of the procedure if there is a select statement in it. Also, after the Fill() command you can access output.Value as mentioned in the above code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Grouped Table View in which I want to display Contact details. But
Just an introduction of my code... I have a view that consists of -details
i have view like 'home/details/5', it can be access by anonymous user. but there
OK so I have a strongly-typed Customer Details view that takes a Customer object
I would like to have something that would kind of replicate the details view
I have a View that works but I can not figure out how to
I have a user control I have created that contains a details-view that I
I am using ASP.MVC 3. I have a view that has a textarea on
I have a System.Windows.Forms.ListView control that I was using with View = View.List .
I have a view that is showing details of my post with comments, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.