hey im using vs 2012 and sql 2012 .net framework 4.5

i have searched loads now and found different examples and tried different samples and have found nothing that works. my db has a primary key which is the idx i also want the username to be unique which i cannot do

im using windows forms connecting to a wcf service

sample code im using in the wcf to add to the db is:#

public DataSet SelectUserDetails()
{

SqlConnection con = new SqlConnection("blah blah");

con.Open();

SqlCommand cmd = new SqlCommand("Select * from RegistrationTable", con);

SqlDataAdapter sda = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

sda.Fill(ds);

cmd.ExecuteNonQuery();

con.Close();

return ds;

}



public string InsertUserDetails(UserDetails userInfo)
{

string Message;

SqlConnection con = new SqlConnection("blah blah");

con.Open();

SqlCommand cmd = new SqlCommand("insert into RegistrationTable(Username,Password) values(@UserName,@Password)", con);

cmd.Parameters.AddWithValue("@UserName", userInfo.UserName);

cmd.Parameters.AddWithValue("@Password", userInfo.Password);

int result = cmd.ExecuteNonQuery();

if (result == 1)
{

Message = userInfo.UserName + " Details inserted successfully";

}

else
{

Message = userInfo.UserName + " Details not inserted successfully";

}

con.Close();

return Message;

}
}

}
my windows form code is as follows#

private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.UserDetails objuserdetail = new ServiceReference1.UserDetails();

objuserdetail.UserName = textBox1.Text;

objuserdetail.Password = textBox2.Text;

obj.InsertUserDetails(objuserdetail);

}






any help will be amazing, like i said been searching for ages, and am lost as to what to do

regards

Dean