protected void Button1_Click1(object sender, EventArgs e)
{
string sql = "INSERT INTO user(CustomerName,Age,Sex,Email address,State,City,Country) VALUES (@Val1,@Val2,@val3,@val4,@val5,@val6,@val7,@val8,@val9,@val10)";
try
{
SqlConn.Open();
SqlCommand cmd = new SqlCommand(sql, SqlConn);
cmd.Parameters.AddWithValue("@Val1", txtcname.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@Val2", txtAge.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@Val3", txtsex.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@Val4", txtEmail.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@Val5", txtaddress.Text.ToString().Trim());
cmd.Parameters.AddWithValue("@val6", DrpState.SelectedItem.ToString().Trim());
cmd.Parameters.AddWithValue("@Val7", DrpCity.SelectedItem.ToString().Trim());
cmd.Parameters.AddWithValue("@Val7", DrpCountry.SelectedItem.ToString().Trim());
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
SqlConn.Close();
}
}
this is my coding..
it is working fine ..
but problem is same customer register twice and it stored into table twice.. i need to solve this problem..
if user name already taken by another user i need to receive error message.(user name already exists pls provide another user name )
pls help me where can i change my coding..
Thanks in advance..