Click here to Skip to main content
15,844,752 members

Comments by R.M49 (Top 44 by date)

R.M49 28-Apr-17 14:56pm View    
the if statment doesn't contain the insertstatement, it contains the error message that I wrote it. I want to display the error message that I put in dr.hasraw statment when the username is duplicated, I don't want to get an error page from the browser I want to show my error message. What I want is to show a message box if the username exists.
R.M49 27-Apr-17 17:58pm View    
Ok I tried the below code and I tested it with button and it worked, but know I want to assign it to the insert command of the detailsview. I tried to put it in DetailsView1_ItemInserting but in case of if statement it gives me the yellow error page with PK duplication, but in case of else statement is works fine. Any Help??

Hide   Copy Code
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)        {            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);            string query = "select Username from [Login] where Username = '" + ((TextBox)DetailsView1.FindControl("TextBox1")).Text + "'";            SqlCommand cmd = new SqlCommand(query, con);            con.Open();            SqlDataReader dr = cmd.ExecuteReader();                        dr.Read();            if (dr.HasRows == true)            {                 Response.Write("<script>alert('Username is Already Exists')</script>");             }            else            {                Response.Write("<script>alert('SuccessFully Saved')</script>");            }             con.Close();        }
R.M49 27-Apr-17 7:31am View    
how to fix it
R.M49 26-Apr-17 15:26pm View    
As I wrote nothing.
R.M49 26-Apr-17 15:16pm View    
the button click is with detailsview (InsertCommand), I tried to but it in item inserting and item inserted but it didn't work