Dear sir,
I am inserting data through gridview. and again click on submit button with same data it display inserted successfully.
I want to display error message record already existed. Please help me and send code.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 27, 2012, 10:37 PM EST
murali athmuri34 reputationPosted Dec 27, 2012, 11:29 PM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 12:16 AM EST
murali athmuri34 reputationPosted Dec 28, 2012, 12:46 AM EST
I am sending by designing page.
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 2:02 AM EST
create a stroed procedure as follows
createPROCEDURE insertData
(
@ID int,
@Name varchar(50),
@Address varchar(50)
)
as
begin
iF NOT EXISTS (
select * from Employee
where EmployeeName = @Name AND Address = @Address) // here compare with your desired column
insert into Employee(EmpID,EmployeeName,Address)values(@ID,@Name,@Address)
END
from your code
string constring = ConfigurationManager.ConnectionStrings["vendorConn"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("insertData",sqlCon);
cmd.Parameters.AddWithValue("@ID", 2000);
cmd.Parameters.AddWithValue("@Name", "Dorababu");
cmd.Parameters.AddWithValue("@Address", "Hyderabad");
cmd.CommandType = CommandType.StoredProcedure;
sqlCon.Open();
if (cmd.ExecuteNonQuery() > 0)