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 6850833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:10:24+00:00 2026-05-27T01:10:24+00:00

I have a series of data that need to be written into SQL, what

  • 0

I have a series of data that need to be written into SQL, what should I do to check the data in SQL to prevent same data inserted into table?

Example data to be inserted:

David  
James  
John  

If the 4th data is John again, I want the system to skip the duplicate record (John).

So far I have:

SqlConnection myCnn = new SqlConnection(cnn);
String _state = "Insert into CamNo1(platename, date, camID, path, filename) OUTPUT INSERTED.platename values(@msg, getdate(), @camID, @path, @filename)";
SqlCommand _Query = new SqlCommand(_state, myCnn);

_Query.Parameters.AddWithValue("@msg", msg);
_Query.Parameters.AddWithValue("@camID", camID);
_Query.Parameters.AddWithValue("@path", imageFile);
_Query.Parameters.AddWithValue("@filename", name);

try
{
   myCnn.Open();
   string checkname = (string)_Query.ExecuteScalar();
   myCnn.Close();

   getcheckname = checkname;
   Console.WriteLine("OK");
}
catch (Exception)
{
}

i got the string value checkname that is last inserted, what should i do check the data?

  • 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-05-27T01:10:25+00:00Added an answer on May 27, 2026 at 1:10 am

    First, you can prevent a duplicate from ever occurring in the table by using a unique index or constraint. An index/constraint can work in concert with the suggestions below. If you only use a unique index and not one of the below solutions, inserting a duplicate record will throw an error and you will need to handle that on the other end.

    Additionally, I would probably insert the data via a stored procedure that checks to see if the row already exists. To do that, you can use either a MERGE statement, as shown in this pseudo code:

    create procedure MyProcedure
    (
        @Name nvarchar(100),
        ...
    )
    as
    
    merge MyTable
    using
    (
        select @Name,...
    ) as source (Name, ...)
    on MyTable.Name = source.Name
    when not matched then
        insert (Name,...) values (source.Name,...)
    when matched then
        update set Name = @Name,...
    

    or, you could check for the records existence and insert or update manually:

    create procedure MyProcedure
    (
        @Name nvarchar(100),
        ...
    )
    as
    
        if not exists (select * from MyTable where Name = @Name)
        begin
            insert into MyTable (Name,...) values (@Name,...)
        end
        else
        begin
                update MyTable
                set ...
                where Name = @Name
        end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data which represents a series of events that persons
I have a table of time-series data of which I need to find all
I have a series of tables that contain data I want to full text
Well I have a series of sps that are running a data warehousing solution
I have a (C#) genetic program that uses financial time-series data and it's currently
I have some time-series data that I'm fitting a loess curve in ggplot2, as
I have a series of large, flat text files that I need to parse
I have a set of actions that are returning time-series data with-in ranges specifiable
I have a series of API calls that are returning J# data types. I
I have a scenario where I need to send a series of data across

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.