.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

restrict data duplication in data base

Posted By: Nabin     Posted Date: January 16, 2010    Points:2   Category :ASP.Net
Hi every one

I have one problem. i m just developing a simple user registration form using asp.net2.0. so i just want to restrict duplication in user registration. i m using sqlserver 2005 as database.


what should be done for that???
can anyone help on that plzzzzzzzzzz

Thanks & Regards
Nabin

Responses
Author: Rahul             
Posted Date: January 16, 2010     Points: 5   

Hi,

You can do the SQL Server Query level itself. For eg

if(Select * from User_Table where user_name = 'userval')

select 0;

else

Select 1;


And in the front end you can check the return value if its o means user name is available and if returned value is 1 means user name is available.

Rahul

Author: Lalij Mer             
Posted Date: January 17, 2010     Points: 5   

show here

http://www.eggheadcafe.com/community/aspnet/7/10019272/login-validation.aspx

Please Check my answer if you help....
Thank You...

Lalit.
Author: Nabin             
Posted Date: January 19, 2010     Points: 5   

hi
thanks so much for the response. But tht is not what i m needed. just see the requirement again plzzzz.
i have a simple user registration form in which i want to restrict duplicate user registration. Means if a user have registered with a email address then for the next time it don't allows him to register again with the same email id if the id is once present in the data base. And simple shows a message tht
"User is already in the database"



Thanks & Regards
Nabin

Author: Prasanti Prusty             
Posted Date: January 26, 2010     Points: 5   

Hi,

Use the following Codes for validation.

Imports System.Data
Imports System.Data.SqlClient
Partial Class Default8
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objDS As New DataSet
Dim objSDA As New SqlDataAdapter
Dim objCmd As New SqlCommand
Dim objSqlCon As New SqlConnection
Try
objSqlCon.ConnectionString = "Password=ZZZ;Persist Security Info=True;User ID=ZZZ;Initial Catalog=ZZZ;Data Source=ZZZ"
objSqlCon.Open()
objCmd.Connection = objSqlCon
objCmd.CommandText = "SELECT * FROM tbUserMst WHERE EmailID='" & TextBox1.Text.Trim & "'"
objCmd.CommandType = CommandType.Text
objSDA.SelectCommand = objCmd
objSDA.Fill(objDS)
If objDS.Tables.Count > 0 Then
If objDS.Tables(0).Rows.Count > 0 Then
ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script>alert('User is already in the database');</script>")
End If
End If
Catch ex As Exception

End Try
End Sub
End Class


Regards,
Prasanti
Author: Nabin             
Posted Date: January 27, 2010     Points: 5   

Thanks Chikul
but can u give the c# code plzzz


Thanks & Regards
Nabin

Author: Prasanti Prusty             
Posted Date: January 27, 2010     Points: 5   

Hi,

C# Coding


using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet objDS=new DataSet();
SqlDataAdapter objSDA=new SqlDataAdapter();
SqlCommand objCmd= new SqlCommand();
SqlConnection objSqlCon = new SqlConnection();

try
{
string strQry = TextBox1.Text;
objSqlCon.ConnectionString = "Password=CC;Persist Security Info=True;User ID=CC;Initial Catalog=CC;Data Source=CC";
objSqlCon.Open();
objCmd.Connection = objSqlCon;
objCmd.CommandText = "SELECT * FROM tbUserMst WHERE EmailID='" + strQry + "'";
objCmd.CommandType = CommandType.Text;
objSDA.SelectCommand = objCmd;
objSDA.Fill(objDS);
if(objDS.Tables.Count > 0)
{
if(objDS.Tables[0].Rows.Count > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script>alert('User is already in the database');</script>");
}
}
}
catch(Exception )
{
throw;
}
}
}


Regards,
Prasanti
Author: Nabin             
Posted Date: February 02, 2010     Points: 5   

Thanks a lot Chikul




Nabin

Author: Prasanti Prusty             
Posted Date: February 02, 2010     Points: 5   

Wel Come

Regards,
Chikul

Regards,
Prasanti


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend