I need to stop duplicate records in my sql table and if data exists how can i show message says already exists this is my code below :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace cap
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-6I0G8AT;Initial Catalog=cap;Integrated Security=True");
con.Open();
string store = "INSERT INTO Customer (Cust_Name,Cust_Username,Cust_Email,Cust_Contact,Cust_Password ) VALUES (@Cust_Name,@Cust_Username,@Cust_Email,@Cust_Contact,@Cust_Password)";
SqlCommand cmd = new SqlCommand(store,con);
cmd.Parameters.AddWithValue("@Cust_NAME", txtfirstname.Text + " " + txtlastname.Text);
cmd.Parameters.AddWithValue("@Cust_Username", txtusername.Text);
cmd.Parameters.AddWithValue("@Cust_Email", txtemail.Text);
cmd.Parameters.AddWithValue("@Cust_Contact", txtcontact.Text);
cmd.Parameters.AddWithValue("@Cust_Password", txtpassword.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Mageshwaran RPosted Nov 23, 2019, 12:58 PM
Rajanikant HawaldarPosted Jun 2, 2019, 11:52 PM
Jignesh KumarPosted Jun 2, 2019, 11:40 PM
Gajendra JangidPosted Jun 2, 2019, 9:14 AM
Anoop Kumar SharmaPosted Jun 2, 2019, 6:55 AM
Faisal PathanPosted Jun 2, 2019, 6:23 AM