Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hi this is my code
i want to check year and month

C#
System.Collections.Specialized.ListDictionary listDictionary
       = new System.Collections.Specialized.ListDictionary();
            listDictionary.Add("UserName", TextBox6.Text);
            listDictionary.Add("DisplayName", TextBox7.Text);
            listDictionary.Add("Year", TextBox8.Text);
            listDictionary.Add("Month", TextBox9.Text);
            listDictionary.Add("Fee", TextBox5.Text);
            listDictionary.Add("Transactions", TextBox10.Text);

            LinqDataSource3.Insert(listDictionary);
Posted
Updated 28-Oct-13 23:41pm
v3

A Better way to avoid Duplicate record is TO make that Column Unique in database Check
this
 
Share this answer
 
v2
Hi,
You have multiple options to avoid duplicate insertion of data into Database.
Option 1:
Make the Username field as Primary Key/ Unique Key, so the same username data will not be inserted, which in turn throws an exception. You handle the appropriate exception and intimate the user.
Note: Here the Exception handling block and checking Database and throwing SL exception is more cost effective.

Option 2:
Create a Stored procedure and check for username availability with the Distinct of data in table.
Public bool GetUserAvaliablity(Username)
If the data is already available then intimate user.


C#
List<string> lstUserName = new List<string>();

           lstUserName.Add("Rajesh");
           lstUserName.Add("Anand");
           lstUserName.Add("Venky");
           lstUserName.Add("Prabhu");
           lstUserName.Add("Balu");

           var userName = from name in lstUserName
                             where name == "Balu"
                             select name;


           if(userName.ToString().Length > 0)
           {
               Console.WriteLine("Name Exists");
           }
 
Share this answer
 
v2
1.make that field "Unique".

2.make that field as "Primary key".

3.Explicitly check whether the entry is duplicate or not by executing select query.
i.e
You want to check either year or month is duplicate then...
SQL
SELECT USER_NAME FROM TABLE WHERE YEAR == TXTYEAR OR MONTH == TXTMONTH;

You want to check for both shouldn't be duplicate then...
SQL
SELECT USER_NAME FROM TABLE WHERE YEAR == TXTYEAR AND MONTH == TXTMONTH;

Here if you found any row it means there is already a record with same year and month.

Hope This Help
-----------------
Pratik Bhuva
 
Share this answer
 
Comments
Member 10319738 30-Oct-13 2:06am    
i got myself
I have already made UserId as primary Key and Unique in MSSQL Server table inspite of that sometimes duplicate entry is made.
Actually, members are joined with ID (Auto generated), we can't restrict same names from being registered as ID generated by system is to be unique.
can anybody help to fix this issue.
I have also tried redirect, sometime user clicks twice, if there any solution that user could not click twice, plz. help
problem only comes when user by mistake click twice.
If I try some javascript code to disable button on click, there is some server side validation, after that again need to enable button
 
Share this answer
 

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