protected void btnRegister_Click(object sender, EventArgs e) { string connetionString = "Data Source=qweq;Initial Catalog=Test_DB;User ID=asd;Password=asdsf"; SqlConnection conn = new SqlConnection(connetionString); string commText = "insert into login(User_Name,Password,Address,City,State,PIN,Phone_no,Email_id,Created_By,Created_on) values('" + txtUserName.Text + "','" + txtPassword.Text + "','" + txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + Convert.ToDouble(txtPin.Text) + "','" + Convert.ToDouble(txtPhoneNo.Text) + "','" + txtEmailId.Text + "','" + "Alok" + "','" + DateTime.Now + "')"; SqlCommand cmd = new SqlCommand(commText, conn); conn.Open(); int no = cmd.ExecuteNonQuery(); conn.Close(); if(no>0) { Label1.Text= "User register register sucessfully"; } else { Label1.Text = "Error"; } txtUserName.Text = String.Empty; txtPassword.Text = String.Empty; txtAddress.Text = String.Empty; txtCity.Text = String.Empty; txtState.Text = String.Empty; txtPin.Text = String.Empty; txtPhoneNo.Text = String.Empty; txtEmailId.Text = String.Empty; }
EXISTS
if not exists (select *from login where username=@username) begin --Insert Query end else begin --Update Query or something.. end
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)