|
-
October 17th, 2012, 05:13 PM
#3
Re: Prevent duplicate username insert wcf help
hey thanks for response i now have my idx as unique and my username set to unique too. i tested it and it threw an exception,
only thing is now i get this error and cant work it out
Error 1 'WcfService1.Service1.InsertUserDetails(WcfService1.UserDetails)': not all code paths return a value
my code is
public string InsertUserDetails(UserDetails userInfo)
{
string connection = @"blah blah blah";
SqlConnection con = new SqlConnection(connection);
try
{
con.Open();
if (con.State.Equals(System.Data.ConnectionState.Open))
{
try
{
SqlCommand cmd = new SqlCommand("insert into Query(UserName,Password,Country,Email) values(@UserName,@Password,@Country,@Email)", con);
cmd.Parameters.AddWithValue("@UserName", userInfo.UserName);
cmd.Parameters.AddWithValue("@Password", userInfo.Password);
cmd.Parameters.AddWithValue("@Country", userInfo.Country);
cmd.Parameters.AddWithValue("@Email", userInfo.Email);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{ //next statement
con.Close(); }
else
{ //next statement
con.Close(); }
}
catch (SqlException exception)
{
if (exception.Number == 2601) //2627)
{
throw new FaultException("Sorry Username Is Taken.", new FaultCode("Insert Fault"));
}
else
{ }
}
catch (Exception)
{
throw new FaultException("There was a problem connecting to the database.", new FaultCode("ConnectionFault"));
}
}
}
finally
{ }
}
}
}
any advice will be great ty
Dean
Last edited by VirUs1234; October 17th, 2012 at 05:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|